Could someone introduce an use case for AutoResetEvent.Reset() method ? When and why I would like to use this method ? I understand WaitOne and Set but this is quite unclear for me.
You can control the initial state of an AutoResetEvent by passing a Boolean value to the constructor: true if the initial state is signaled and false otherwise. AutoResetEvent can also be used with the static WaitAll and WaitAny methods.
An AutoResetEvent resets when the code passes through event. WaitOne() , but a ManualResetEvent does not.
Set to signal that the waiting threads can proceed. All waiting threads are released. Once it has been signaled, ManualResetEvent remains signaled until it is manually reset by calling the Reset() method. That is, calls to WaitOne return immediately.
Yes the AutoResetEvent
will automatically reset it's state whenever a thread which is waiting on the event is signaled. However it's possible that a given event is no longer valid and no thread has waited on an AutoResetEvent
since it was originally set. In that scenario the Reset
method becomes useful
Looks like it's just inherited from EventWaitHandle. Probably more useful with the ManualResetEvent which also inherits from that class?
The method is inherited from the base class EventWaitHandle
and is used to (re)set an AutoResetEvent
to its "blocked" state.
Because AutoResetEvent
will automatically enter that state as soon as it's signalled, you'll typically never see this method used in code, but for other classes deriving from EventWaitHandle
it would be much more useful!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With