Two important notes
There is no guarantee that every call to the Set method will release a thread. If two calls are so close together that the second call occurs before a thread has been released, only one thread is released. It is as if the second call did not occur.
Also, if Set is called when there are no threads waiting and the AutoResetEvent is already signaled, the call has no effect.
If Set
is called when no thread is waiting, the handle stays open for as long as it takes until some thread calls WaitOne
. This behavior helps avoid a race between a thread heading for the turnstile, and a thread inserting a ticket (“Oops, inserted the ticket a microsecond too soon, bad luck, now you’ll have to wait indefinitely!”). However, calling Set
repeatedly on a turnstile at which no one is waiting doesn’t allow a whole party through when they arrive: only the next single person is let through and the extra tickets are “wasted.” http://www.albahari.com/threading/part2.aspx#%5FProducerConsumerQWaitHandle