How to wait for thread to finish with .NET?
- by Maxim Z.
I've never really used threading before in C# where I need to have two threads, as well as the main UI thread. Basically, I have the following.
public void StartTheActions()
{
//Starting thread 1....
Thread t1 = new Thread(new ThreadStart(action1));
t1.Start();
//Now, I want for the main thread (which is calling StartTheActions() ) to wait for t1 to finish (I have created an event in action1() for this) and then start t2...
//HOW DO I DO THIS?
Thread t2 = new Thread(new ThreadStart(action2));
t2.Start();
}
So, essentially, my question is how to have a thread wait for another one to finish. What is the best way to do this? Thanks!