I have read the documentation on this and I think I understand. An AutoResetEvent
resets when the code passes through event.WaitOne()
, but a ManualResetEvent
does not.
Is this correct?
ManualResetEvent is used for send signals between two or more threads. Multiple threads can enter into a waiting/blocking state by calling the WaitOne method on ManualResetEvent object. When controlling thread calls the Set method all the waiting threads are unblocked and free to proceed.
Start the main thread; When an asynchronous worker thread is triggered, call the ManualResetEvent object's WaitOne() method to block the main thread; When the worker thread has completed, call the ManualResetEvent object's Set() method to release the main thread and allow it to continue.
Yes. It's like the difference between a tollbooth and a door. The ManualResetEvent
is the door, which needs to be closed (reset) manually. The AutoResetEvent
is a tollbooth, allowing one car to go by and automatically closing before the next one can get through.
Just imagine that the AutoResetEvent
executes WaitOne()
and Reset()
as a single atomic operation.
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