Customize the StartProc for thread

  • Thread starter Thread starter Zeng
  • Start date Start date
Z

Zeng

Hello,

Is there a way to pass something to the StartProc below for each new thread
that I create? Something like 'code' below. Thanks for any comment or
advice!

static void StartProc( int code )
{
if( code > 0 )
{
// do something
}
}

Thread t = new Thread( new ThreadStart(StartProc));
t.Start();
 
You could use a property, but then StartProc is a static method, so the
only way you can do this is by using delegate because delegate can take
parameters. Try to do some research on delegate online and get some
samples. I'm sure there is a lot out there.
 
I'm still not clear on how to pass in something (id, string etc...) to the
StartProc. The ThreadStart is defined by .net and it's a delegate of
no-parameter method type.
 
ThreadStart IS defined as no-parameter delegate, but it can belong to
statfull instance of a class, so that instance can carry context information
for the Thread procedure.

Leonid Finis.
 
Back
Top