I am just a beginner."ParameterizedThreadStart" accepts single object as argument.
Is there any other delegate signature allows me to
(1) pass params (variable number of parameter) on thread?
(2) support generic parameters like list ?
I am just a beginner."ParameterizedThreadStart" accepts single object as argument.
Is there any other delegate signature allows me to
(1) pass params (variable number of parameter) on thread?
(2) support generic parameters like list ?
You can use Delegate.BeginInvoke and EndInvoke, to pass any parameters you want
delegate long MyFuncDelegate(int N );
MyFuncDelegate cpn = new MyFuncDelegate(MyFunc);
IAsyncResult ar = cpn.BeginInvoke( 3, null, null );
// Do some stuff
while( !ar.IsCompleted )
{
// Do some stuff
}
// we now know that the call is
// complete as IsCompleted has
// returned true
long answer = cpn.EndInvoke(ar);
You can do anything you want with a single object. Just define a class to wrap the parameters you are interested in:
class ThreadState
{
public ThreadState()
{
}
public string Name
{
get;
set;
}
public int Age
{
get;
set;
}
}
// ...
ParameterizedThreadStart start = delegate(object objThreadState)
{
// cast to your actual object type
ThreadState state = (ThreadState)objThreadState;
// ... now do anything you want with it ...
};