Show / Hide Table of Contents

Class AsyncCountdownEvent

Represents a synchronization primitive that is signaled when its count reaches zero.

Inheritance
object
Disposable
QueuedSynchronizer
AsyncCountdownEvent
Implements
IAsyncEvent
IDisposable
IResettable
Inherited Members
QueuedSynchronizer.MeasurementTags
QueuedSynchronizer.TrackSuspendedCallers(Func<object>)
QueuedSynchronizer.SetCallerInformation(object)
QueuedSynchronizer.GetSuspendedCallers()
QueuedSynchronizer.CancelSuspendedCallers(CancellationToken)
QueuedSynchronizer.Dispose(bool)
QueuedSynchronizer.Dispose(Exception)
QueuedSynchronizer.DisposeAsyncCore()
QueuedSynchronizer.DisposeAsync()
Disposable.IsDisposed
Disposable.IsDisposing
Disposable.IsDisposingOrDisposed
Disposable.CreateException()
Disposable.DisposedTask
Disposable.GetDisposedTask<T>()
Disposable.TrySetDisposedException<T>(TaskCompletionSource<T>)
Disposable.TrySetDisposedException(TaskCompletionSource)
Disposable.TryBeginDispose()
Disposable.Dispose()
Disposable.Dispose(IEnumerable<IDisposable>)
Disposable.DisposeAsync(IEnumerable<IAsyncDisposable>)
Disposable.Dispose<T>(ReadOnlySpan<T>)
Disposable.DisposeAsync(params IAsyncDisposable[])
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
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 Source

AsyncCountdownEvent(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

initialCount is less than zero.

| Edit this page View Source

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

initialCount is less than zero; or concurrencyLevel is less than or equal to zero.

Properties

| Edit this page View Source

CurrentCount

Gets the number of remaining signals required to set the event.

Declaration
public long CurrentCount { get; }
Property Value
Type Description
long
| Edit this page View Source

InitialCount

Gets the numbers of signals initially required to set the event.

Declaration
public long InitialCount { get; }
Property Value
Type Description
long
| Edit this page View Source

IsSet

Indicates whether this event is set.

Declaration
public bool IsSet { get; }
Property Value
Type Description
bool

Methods

| Edit this page View Source

AddCount()

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.

| Edit this page View Source

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

signalCount is less than zero.

InvalidOperationException

The current instance is already set.

| Edit this page View Source

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.

| Edit this page View Source

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

count is less than zero.

| Edit this page View Source

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

signalCount is less than 1.

InvalidOperationException

The current instance is already set; or signalCount is greater than CurrentCount.

| Edit this page View Source

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.

| Edit this page View Source

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

signalCount is less than zero.

| Edit this page View Source

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.

| Edit this page View Source

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>

true if signaled state was set; otherwise, false.

Exceptions
Type Condition
ObjectDisposedException

The current instance has already been disposed.

ArgumentOutOfRangeException

timeout is negative.

OperationCanceledException

The operation has been canceled.

Implements

IAsyncEvent
IDisposable
IResettable

Extension Methods

BasicExtensions.As<T>(T)
BasicExtensions.GetUserData<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
ExpressionBuilder.Const<T>(T)
AsyncLockAcquisition.AcquireLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, TimeSpan, CancellationToken)
LockAcquisition.AcquireReadLock<T>(T)
LockAcquisition.AcquireReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireUpgradeableReadLock<T>(T)
LockAcquisition.AcquireUpgradeableReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireWriteLock<T>(T)
LockAcquisition.AcquireWriteLock<T>(T, TimeSpan)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾