AutoResetEvent.Set 方法
定义
将事件状态设置为终止,从而最多允许一个等待线程继续执行。Sets the state of the event to signaled, which allows at most one waiting thread to proceed.
public:
bool Set();
public bool Set ();
member this.Set : unit -> bool
Public Function Set () As Boolean
返回
如果该操作成功,则为 true;否则为 false。true if the operation succeeds; otherwise, false.
注解
Set 方法释放单个线程。The Set method releases a single thread. 如果没有等待线程,则等待句柄会保持终止状态,直到某个线程尝试等待它,或者直到其重置方法被调用为止。If there are no waiting threads, the wait handle remains signaled until a thread attempts to wait on it, or until its Reset method is called.
重要
不保证每次调用 Set 方法都将释放一个线程。There is no guarantee that every call to the Set method will release a thread. 如果两次调用都过于接近,因此在释放线程之前发生第二次调用,则只释放一个线程,就像第二次调用未发生一样。If two calls are too close together, so that the second call occurs before a thread has been released, only one thread is released - as if the second call did not happen. 此外,如果在没有等待的线程并且已发出信号的情况下调用 Set 方法 AutoResetEvent ,则调用不起作用。Also, if the Set method is called when there are no threads waiting and the AutoResetEvent is already signaled, the call has no effect.