Reputation: 3
enter image description herehello I want to ask is there a way to create a new thread to start the function and send information to it. something like the info i need to send to join the thread or something like that.
This is What i mean:
private Thread T1;
private Thread T2;
public void Start()
{
string NaMES = "DEMO";
int AGE = Convert.ToInt32("44");
T1 = new Thread(Here(NaMES, AGE));
T1.Start();
}
public object Here(string NAME, int AGE)
{
MessageBox.Show(NAME + AGE);
return null;
}
Upvotes: 0
Views: 49
Reputation: 21251
Thread
has an overloaded constructor that allows you to pass a single parameter, so you could create an object that holds all the data required by your thread delegate.
But probably simpler is to just use a lambda to create a closure around your variables automatically:
T1 = new Thread(() => Here(NaMES, AGE));
Upvotes: 3