AutoResetEvent RRS feed

  • Question

  • I still can't understand how AutoResetEvent works.. though use it for years.

    When it comes to Set() then should somewhere already be a part of code awaiting for WaitOne()?.

    In other words.. if Set() has been successfully before WaitOne(), will it be Reset automatically before WaitOne() and I will miss Set?

    or in other words - Does WaitOne() makes the reset of the flag or not?.

    Thanks you

    "I = I + 1" .. Isn't it boolshit?

    • Edited by RobbKirk Tuesday, December 10, 2019 7:17 AM
    Tuesday, December 10, 2019 6:59 AM


  • Hi RobbKirk,
    As official document states, calling set signals AutoResetEvent to release a waiting thread. AutoResetEvent remains signaled until a single waiting thread is released, and then automatically returns to the non-signaled state. If no threads are waiting, the state remains signaled indefinitely.
    If a thread calls WaitOne while the AutoResetEvent is in the signaled state, the thread does not block. The AutoResetEvent releases the thread immediately and returns to the non-signaled state.
    A thread waits for a signal by calling AutoResetEvent.WaitOne. If the AutoResetEvent is in the non-signaled state, the thread blocks until AutoResetEvent.Set is called.
    Besides, 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.
    More details you can refer to this document.
    [AutoResetEvent Class]
    Best Regards,
    Daniel Zhang

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, December 10, 2019 9:05 AM