How to pass data to a thread?

  • Thread starter Thread starter Faraz Rasheed
  • Start date Start date
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);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top