F
Faraz Rasheed
How can I pass some data to a thread. I tried GetData() and SetData()
methods of Thread class but couldn’t solve the problem. Consider the
following code
public void SomeMethod(int somevalue)
{
Thread t = new Thread(thFunc);
// make variable ‘somevalue’ accessible to the thread t
t.Start();
return;
}
public void thFunc()
{
int valuehere;
// retrieve the value of variable ‘somevalue’ and store it to vaiable
‘valuehere’
// the following line should print the value of variable ‘somevalue’
Console.WriteLine(valuhere);
}
methods of Thread class but couldn’t solve the problem. Consider the
following code
public void SomeMethod(int somevalue)
{
Thread t = new Thread(thFunc);
// make variable ‘somevalue’ accessible to the thread t
t.Start();
return;
}
public void thFunc()
{
int valuehere;
// retrieve the value of variable ‘somevalue’ and store it to vaiable
‘valuehere’
// the following line should print the value of variable ‘somevalue’
Console.WriteLine(valuhere);
}