相关疑难解决方法(0)

如何等待线程完成.NET?

我以前从未在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)

所以,基本上,我的问题是如何让一个线程等待另一个线程完成.做这个的最好方式是什么?

c# multithreading

167
推荐指数
5
解决办法
32万
查看次数

标签 统计

c# ×1

multithreading ×1