static object locker = new object(); public void A() { while (true) { lock (locker) { //A // do some thing Monitor.Pulse(locker); Monitor.Wait(locker); } } }
public void B() { while (true) { lock (locker) { //B //do some thing Monitor.Pulse(locker); Monitor.Wait(locker); } } }
thread.Join();可以阻塞其他线程,直到当前线程执行接收,类似Task里的wait;