Pass Parameters through ParameterizedThreadStart

c#, multithreading

Solution

lazyberezovsky has the right answer. I want to note that technically you can pass an arbitrary number of arguments using lambda expression due to variable capture:

var thread = new Thread(
       () => DoMethod(a, b, c));
thread.Start();

This is a handy way of calling methods that don't fit the `ThreadStart` or `ParameterizedThreadStart` delegate, but be careful that you can easily cause a data race if you change the arguments in the parent thread after passing them to the child thread's code.

Problem

I'm trying to pass parameters through the following: ``` Thread thread = new Thread(new ParameterizedThreadStart(DoMethod)); ``` Any idea how to do this? I'd appreciate some help

Original source