c#中等待某个线程执行完后再执行某个线程

在方法的外部申请一个这样的变量
CountdownEvent latch = new CountdownEvent(3);
比如现在执行的是方法a
public void a()
{
int si=0,ei=0;
Thread thread = new Thread(() => refreshData(si, ei));
thread .start();
thread = new Thread(() => refreshData(si, ei));
thread .start();
thread = new Thread(() => refreshData(si, ei));
thread .start();
latch.Wait();
MessageBox.Show(start.ToString() + “,,,” + end.ToString());
}
private void refreshData(int start, int end)
{
latch.Signal();
}
这样会等到三个线程全部执行完后才会出现 messagebox提示框,

你可能感兴趣的:(Asp.Net)