Thread.Join方法在c#中有什么意义?

Tec*_*hee 10 c# multithreading

Thread.Join方法在c#中有什么意义?

MSDN表示它会阻塞调用线程,直到线程终止.有人可以用一个简单的例子解释一下吗?

Spi*_*ike 14

Join() 基本上是 while(thread.running){}

{
  thread.start()
  stuff you want to do while the other thread is busy doing its own thing concurrently
  thread.join()
  you won't get here until thread has terminated.
} 
Run Code Online (Sandbox Code Playgroud)


and*_*ecu 8

int fibsum = 1;

Thread t = new Thread(o =>
                          {
                              for (int i = 1; i < 20; i++)
                              {
                                  fibsum += fibsum;
                              }
                          });

t.Start();
t.Join(); // if you comment this line, the WriteLine will execute 
          // before the thread finishes and the result will be wrong
Console.WriteLine(fibsum);
Run Code Online (Sandbox Code Playgroud)