我如何等待 n 个脉冲?
… // do something
waiter.WaitForNotifications();
我希望上面的线程等待直到被通知 n 次(被 n 个不同的线程或 n 次被同一个线程通知)。
我相信有一种计数器可以执行此操作,但我找不到。
最佳答案
看看 CountdownEvent Class :
CountdownEvent Class
Represents a synchronization primitive that is signaled when its count reaches zero.
示例:
CountdownEvent waiter = new CountdownEvent(n);
// notifying thread
waiter.Signal();
// waiting thread
waiter.Wait();
关于c# - 让线程等待 n 个脉冲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18144026/