我以前从来没有在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();
}
因此,从本质上讲,我如何让一个线程等待另一个线程完成?做这件事的最好方法是什么?