How to wait for thread to finish with .NET?
Posted
by Maxim Z.
on Stack Overflow
See other posts from Stack Overflow
or by Maxim Z.
Published on 2009-10-18T05:07:13Z
Indexed on
2010/03/24
13:23 UTC
Read the original article
Hit count: 234
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!
© Stack Overflow or respective owner