Wait for a thread to execute before executing a thread in c#

Apply for such a variable
CountdownEvent latch = new CountdownEvent(3) outside the method ; for
example, the method a
public void a() is executed now
{
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();
}In
this way, the messagebox prompt box will appear after all three threads are executed.

Guess you like

Origin blog.csdn.net/hello_mr_anan/article/details/82115878