Is it possible to pass string variable as a WaitCallback parameter in ThreadPool.QueueUserWorkItem()
string myFunction="Go";
ThreadPool.QueueUserWorkItem(MyFunction);
public void Go(object obj)
{
//Do Something
}
You'll need to use reflection.
For example:
WaitCallback callback = (WaitCallback) Delegate.CreateDelegate(
typeof(WaitCallback), this, myFunction);
ThreadPool.QueueUserWorkItem(callback);
To use a method in a different class, change this
to the target instance. If you want to call a static method, use the overload of CreateDelegate
which takes a Type
as the second parameter rather than an object.
See more on this question at Stackoverflow