Tuesday, June 16, 2009

C# 3.5 ParameterizedThreadStart

I wanted to create a Thread that would take a parameter to do concurrency in my project.

This is how I did it.
Thread is in the namespace System.Threading

{
Thread newThread = new Thread(new ParameterizedThreadStart([MethodName]);
newThread.Start([parameter]);
}

[MethodName](object [parameter])
{
// do something
}

So, the key is making the parameter object type. In the method that you created a new thread, convert the object into the datatype that it is.

No comments:

Post a Comment