Class AsyncCountdownEvent
Represents a synchronization primitive that is signaled when its count reaches zero.
Inherited Members
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class AsyncCountdownEvent : QueuedSynchronizer, IAsyncEvent, IDisposable, IResettable
Remarks
This is asynchronous version of CountdownEvent.
Constructors
| Edit this page View SourceAsyncCountdownEvent(long)
Creates a new countdown event with the specified count.
Declaration
public AsyncCountdownEvent(long initialCount)
Parameters
Type | Name | Description |
---|---|---|
long | initialCount | The number of signals initially required to set the event. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
AsyncCountdownEvent(long, int)
Creates a new countdown event with the specified count.
Declaration
public AsyncCountdownEvent(long initialCount, int concurrencyLevel)
Parameters
Type | Name | Description |
---|---|---|
long | initialCount | The number of signals initially required to set the event. |
int | concurrencyLevel | The expected number of suspended callers. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
Properties
| Edit this page View SourceCurrentCount
Gets the number of remaining signals required to set the event.
Declaration
public long CurrentCount { get; }
Property Value
Type | Description |
---|---|
long |
InitialCount
Gets the numbers of signals initially required to set the event.
Declaration
public long InitialCount { get; }
Property Value
Type | Description |
---|---|
long |
IsSet
Indicates whether this event is set.
Declaration
public bool IsSet { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
| Edit this page View SourceAddCount()
Increments the current count by one.
Declaration
public void AddCount()
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The current instance has already been disposed. |
InvalidOperationException | The current instance is already set. |
AddCount(long)
Increments the current count by a specified value.
Declaration
public void AddCount(long signalCount)
Parameters
Type | Name | Description |
---|---|---|
long | signalCount | The value by which to increase CurrentCount. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The current instance has already been disposed. |
ArgumentOutOfRangeException |
|
InvalidOperationException | The current instance is already set. |
Reset()
Resets the CurrentCount to the value of InitialCount.
Declaration
public bool Reset()
Returns
Type | Description |
---|---|
bool | true, if state of this object changed from signaled to non-signaled state; otherwise, false. |
Remarks
All suspended callers will be resumed with PendingTaskInterruptedException exception.
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The current instance has already been disposed. |
Reset(long)
Resets the InitialCount property to a specified value.
Declaration
public bool Reset(long count)
Parameters
Type | Name | Description |
---|---|---|
long | count | The number of signals required to set this event. |
Returns
Type | Description |
---|---|
bool | true, if state of this object changed from signaled to non-signaled state; otherwise, false. |
Remarks
All suspended callers will be resumed with PendingTaskInterruptedException exception.
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The current instance has already been disposed. |
ArgumentOutOfRangeException |
|
Signal(long)
Registers multiple signals with this object, decrementing the value of CurrentCount by the specified amount.
Declaration
public bool Signal(long signalCount = 1)
Parameters
Type | Name | Description |
---|---|---|
long | signalCount | The number of signals to register. |
Returns
Type | Description |
---|---|
bool | true if the signals caused the count to reach zero and the event was set; otherwise, false. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The current instance has already been disposed. |
ArgumentOutOfRangeException |
|
InvalidOperationException | The current instance is already set; or |
TryAddCount()
Attempts to increment the current count by one.
Declaration
public bool TryAddCount()
Returns
Type | Description |
---|---|
bool | true if the increment succeeded; if CurrentCount is already at zero this will return false. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The current instance has already been disposed. |
TryAddCount(long)
Attempts to increment the current count by a specified value.
Declaration
public bool TryAddCount(long signalCount)
Parameters
Type | Name | Description |
---|---|---|
long | signalCount | The value by which to increase CurrentCount. |
Returns
Type | Description |
---|---|
bool | true if the increment succeeded; if CurrentCount is already at zero this will return false. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The current instance has already been disposed. |
ArgumentOutOfRangeException |
|
WaitAsync(CancellationToken)
Turns caller into idle state until the current event is set.
Declaration
public ValueTask WaitAsync(CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | token | The token that can be used to abort wait process. |
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous result. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The current instance has already been disposed. |
OperationCanceledException | The operation has been canceled. |
WaitAsync(TimeSpan, CancellationToken)
Turns caller into idle state until the current event is set.
Declaration
public ValueTask<bool> WaitAsync(TimeSpan timeout, CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | timeout | The interval to wait for the signaled state. |
CancellationToken | token | The token that can be used to abort wait process. |
Returns
Type | Description |
---|---|
ValueTask<bool> |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The current instance has already been disposed. |
ArgumentOutOfRangeException |
|
OperationCanceledException | The operation has been canceled. |