Show / Hide Table of Contents

Class AsyncCounter

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

Inheritance
Object
QueuedSynchronizer
AsyncCounter
Implements
IAsyncEvent
ISynchronizer
IDisposable
Inherited Members
QueuedSynchronizer.ISynchronizer.HasWaiters
QueuedSynchronizer.CancelSuspendedCallers(CancellationToken)
QueuedSynchronizer.Dispose(Boolean)
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class AsyncCounter : QueuedSynchronizer, IAsyncEvent, ISynchronizer, IDisposable
Remarks

This class behaves in opposite to AsyncCountdownEvent. Every call of Increment() increments the counter. Every call of WaitAsync(TimeSpan, CancellationToken) decrements counter and release the caller if the current count is greater than zero.

Constructors

| Improve this Doc View Source

AsyncCounter(Int64)

Initializes a new asynchronous counter.

Declaration
public AsyncCounter(long initialValue = 0L)
Parameters
Type Name Description
Int64 initialValue

The initial value of the counter.

Exceptions
Type Condition
ArgumentOutOfRangeException

initialValue is less than zero.

Properties

| Improve this Doc View Source

Value

Gets the counter value.

Declaration
public long Value { get; }
Property Value
Type Description
Int64
Remarks

The returned value indicates how many calls you can perform using WaitAsync(TimeSpan, CancellationToken) without blocking.

Methods

| Improve this Doc View Source

Increment()

Increments counter and resume suspended callers.

Declaration
public void Increment()
Exceptions
Type Condition
ObjectDisposedException

This object is disposed.

| Improve this Doc View Source

WaitAsync(TimeSpan, CancellationToken)

Suspends caller if Value is zero or just decrements it.

Declaration
public Task<bool> WaitAsync(TimeSpan timeout, CancellationToken token)
Parameters
Type Name Description
TimeSpan timeout

Time to wait for increment.

CancellationToken token

The token that can be used to cancel the waiting operation.

Returns
Type Description
Task<Boolean>

true if counter is decremented successfully; otherwise, false.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

ObjectDisposedException

This object is disposed.

Explicit Interface Implementations

| Improve this Doc View Source

IAsyncEvent.IsSet

Declaration
bool IAsyncEvent.IsSet { get; }
Returns
Type Description
Boolean
| Improve this Doc View Source

IAsyncEvent.Reset()

Declaration
bool IAsyncEvent.Reset()
Returns
Type Description
Boolean
| Improve this Doc View Source

IAsyncEvent.Signal()

Declaration
bool IAsyncEvent.Signal()
Returns
Type Description
Boolean

Implements

IAsyncEvent
ISynchronizer
System.IDisposable

Extension Methods

AsyncLockAcquisition.AcquireLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireUpgradeableReadLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireUpgradeableReadLockAsync<T>(T, CancellationToken)
AsyncEvent.WaitAsync(IAsyncEvent, TimeSpan)
AsyncEvent.WaitAsync(IAsyncEvent, CancellationToken)
AsyncEvent.WaitAsync(IAsyncEvent)
ObjectExtensions.GetUserData<T>(T)
ObjectExtensions.IsOneOf<T>(T, IEnumerable<T>)
ObjectExtensions.IsOneOf<T>(T, T[])
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, Func<T, TResult1>, Func<T, TResult2>, out TResult1, out TResult2)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, ValueFunc<T, TResult1>, ValueFunc<T, TResult2>, out TResult1, out TResult2)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, Func<T, TResult1>, Func<T, TResult2>)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, ValueFunc<T, TResult1>, ValueFunc<T, TResult2>)
ObjectExtensions.As<T>(T)
LockAcquisition.AcquireReadLock<T>(T)
LockAcquisition.AcquireReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireWriteLock<T>(T)
LockAcquisition.AcquireWriteLock<T>(T, TimeSpan)
LockAcquisition.AcquireUpgradeableReadLock<T>(T)
LockAcquisition.AcquireUpgradeableReadLock<T>(T, TimeSpan)
ExpressionBuilder.Const<T>(T)
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX