Class AsyncAutoResetEventSlim
- Namespace
- CounterpointCollective.Threading
- Assembly
- CounterpointCollective.Threading.dll
Represents a lightweight, asynchronous auto-reset event.
public class AsyncAutoResetEventSlim
- Inheritance
-
AsyncAutoResetEventSlim
- Inherited Members
Remarks
This class provides a thread-safe, asynchronous alternative to AutoResetEvent. It allows one waiting task to proceed when the event is set, and automatically resets after a single waiter consumes the event.
Features include:
- Async/await-friendly waiting via WaitOneAsync(CancellationToken).
- Optional synchronous waiting via WaitOne() and overloads with timeout support.
- Termination support via Terminate(), which cancels pending waiters and prevents future sets from having effect.
- Thread-safe querying of event state via IsSet and Terminated.
Usage notes:
- Calling Set() signals the event to release a single waiting task.
- Once Terminate() is called, all current and future waiters will throw ObjectDisposedException.
Constructors
AsyncAutoResetEventSlim(bool)
Represents a lightweight, asynchronous auto-reset event.
public AsyncAutoResetEventSlim(bool startSet)
Parameters
startSetbool
Remarks
This class provides a thread-safe, asynchronous alternative to AutoResetEvent. It allows one waiting task to proceed when the event is set, and automatically resets after a single waiter consumes the event.
Features include:
- Async/await-friendly waiting via WaitOneAsync(CancellationToken).
- Optional synchronous waiting via WaitOne() and overloads with timeout support.
- Termination support via Terminate(), which cancels pending waiters and prevents future sets from having effect.
- Thread-safe querying of event state via IsSet and Terminated.
Usage notes:
- Calling Set() signals the event to release a single waiting task.
- Once Terminate() is called, all current and future waiters will throw ObjectDisposedException.
Properties
IsSet
Gets a value indicating whether the event is currently set.
trueif the event is set and has not yet been consumed by a waiter.falseif the event is not set or if it has been terminated via Terminate().
public bool IsSet { get; }
Property Value
Terminated
public bool Terminated { get; }
Property Value
Methods
Reset()
public void Reset()
Set()
Sets the event, allowing a single waiter to proceed.Typically used to signal that a condition or resource is available for one waiting task.
public void Set()
Remarks
- If the event is already set, this method does nothing.
- If the event has been terminated via Terminate(), calling this method has no effect.
Terminate()
public void Terminate()
WaitOne()
public void WaitOne()
WaitOne(TimeSpan)
public bool WaitOne(TimeSpan t)
Parameters
tTimeSpan
Returns
WaitOneAsync(CancellationToken)
public Task WaitOneAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
WaitOneAsync(TimeSpan)
public Task<bool> WaitOneAsync(TimeSpan t)
Parameters
tTimeSpan