How To Pass An Parameter To A Thread At Start



TODO:

Have you ever wanted to create a thread, and pass a parameter to it when it starts?

 

SOLUTION:

 

//This code creates the thread, and starts it with a parameter
Thread myThread = new Thread(new ParameterizedThreadStart(MyMethodtoCall));	 //create our job thread
myThread.Start(jobStepsToRun);  //start it now, passing in our parameter


//This method will be use in the ParameterizedThreadStart call
private void MyMethodtoCall(object myPassedParameter)
{
     //here you can access your parameter and use it
}

 

NOTES:

There are no notes on this topic.



Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading