Thread procedure with parameter.

  • Thread starter Thread starter Boba
  • Start date Start date
B

Boba

Hello Superiors,

Can someone explain me how can I run thread with
parameter in C# ?

Procedure TX()
{
.... Do something here...
}

Call the TX procedure like this :
tSearch = new Thread(new ThreadStart(TX));

but now I have this one :

Procedure TX(string Test);
{
.... Do something here...
}

What is the way I can run the Thread and sending the
actual paramter ?


With thanks.
 
Create a context wrapper for the thread's work proc:

class MyThreadContext
{
string _test = string.Empty;
public string Test { }
public void WorkProc()
{
// WorkProc has access to the Test string here
}
}

Use it like this:

MyThreadContext ctx = new MyThreadContext();
ctx.Test = "...";
Thread t = new Thread(ctx.WorkProc);
 
Back
Top