Join()Lock()之间的根本区别

2 c# multithreading

对于Join()和lock()的情况,一个线程可以在另一个之后执行.主要区别是什么?

And*_*ith 10

Lock是一个监视器,用于保证一次只能执行1个线程.

lock(myobj)
{
   // only 1 thread here
}
Run Code Online (Sandbox Code Playgroud)

在执行继续之前,Join用于等待线程完成.

anotherThread.Join();
// execution here only when anotherThread is complete
Run Code Online (Sandbox Code Playgroud)