ManualResetEvent 类

ManualResetEvent

通知一个或多个正在等待的线程已发生事件。无法继承此类。

ManualResetEvent 允许线程通过发信号互相通信。通常,此通信涉及一个线程在其他线程进行之前必须完成的任务。

当一个线程开始一个活动(此活动必须完成后,其他线程才能开始)时,它调用 Reset 以将 ManualResetEvent 置于非终止状态。此线程可被视为控制 ManualResetEvent。调用 ManualResetEvent 上的 WaitOne 的线程将阻止,并等待信号。当控制线程完成活动时,它调用 Set 以发出等待线程可以继续进行的信号。并释放所有等待线程。

一旦它被终止,ManualResetEvent 将保持终止状态,直到它被手动重置。即对 WaitOne 的调用将立即返回。

可以通过将布尔值传递给构造函数来控制 ManualResetEvent 的初始状态,如果初始状态处于终止状态,为 true;否则为 false

ManualResetEvent 也可以同 staticWaitAllWaitAny 方法一起使用。

Reset() tells all the threads to hold on while the current thread does its thing.

WaitOne() tells the current thread to chill until it gets a signal that says go ahead.

 

详见 

http://msdn.microsoft.com/zh-cn/library/system.threading.manualresetevent%28v=VS.80%29.aspx

原文地址:https://www.cnblogs.com/76674718/p/2325446.html