我以前从未在C#中使用线程,我需要有两个线程,以及主UI线程.基本上,我有以下几点.
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` method)
// to wait for `t1` to finish. I've created an event in `action1` for this.
// The I wish `t2` to start...
Thread t2 = new Thread(new ThreadStart(action2));
t2.Start();
}
Run Code Online (Sandbox Code Playgroud)
所以,基本上,我的问题是如何让一个线程等待另一个线程完成.做这个的最好方式是什么?