Show / Hide Table of Contents

Class AsyncTimer

Represents asynchronous timer.

Inheritance
Object
AsyncTimer
Implements
IAsyncDisposable
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class AsyncTimer : Disposable, IAsyncDisposable
Remarks

This timer provides guarantees than two executions of timer callback cannot be overlapped, i.e. executed twice or more concurrently at the same time.

Constructors

| Improve this Doc View Source

AsyncTimer(Func<CancellationToken, Task<Boolean>>)

Initializes a new timer.

Declaration
public AsyncTimer(Func<CancellationToken, Task<bool>> callback)
Parameters
Type Name Description
Func<CancellationToken, Task<Boolean>> callback

The timer callback.

Exceptions
Type Condition
ArgumentNullException

callback is null.

| Improve this Doc View Source

AsyncTimer(ValueFunc<CancellationToken, Task<Boolean>>)

Initializes a new timer.

Declaration
public AsyncTimer(ValueFunc<CancellationToken, Task<bool>> callback)
Parameters
Type Name Description
ValueFunc<CancellationToken, Task<Boolean>> callback

The timer callback.

Exceptions
Type Condition
ArgumentNullException

callback is null.

ArgumentException

callback doesn't refer to any method.

Properties

| Improve this Doc View Source

IsRunning

Indicates that this timer is running.

Declaration
public bool IsRunning { get; }
Property Value
Type Description
Boolean

Methods

| Improve this Doc View Source

Dispose(Boolean)

Releases all resources associated with this timer.

Declaration
protected override void Dispose(bool disposing)
Parameters
Type Name Description
Boolean disposing

true if called from ; false if called from finalizer .

| Improve this Doc View Source

DisposeAsync()

Terminates timer gracefully.

Declaration
public ValueTask DisposeAsync()
Returns
Type Description
ValueTask

The task representing graceful shutdown.

| Improve this Doc View Source

Start(TimeSpan, CancellationToken)

Starts the timer.

Declaration
public bool Start(TimeSpan period, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
TimeSpan period

The time interval between invocations of the timer callback.

CancellationToken token

The token that can be used to stop execution of the timer.

Returns
Type Description
Boolean

true if timer was in stopped state; otherwise, false.

| Improve this Doc View Source

Start(TimeSpan, TimeSpan, CancellationToken)

Starts the timer.

Declaration
public bool Start(TimeSpan dueTime, TimeSpan period, CancellationToken token = default(CancellationToken))
Parameters
Type Name Description
TimeSpan dueTime

The amount of time to delay before the invoking the timer callback.

TimeSpan period

The time interval between invocations of the timer callback.

CancellationToken token

The token that can be used to stop execution of the timer.

Returns
Type Description
Boolean

true if timer was in stopped state; otherwise, false.

Exceptions
Type Condition
ObjectDisposedException

The timer has been disposed.

OperationCanceledException

token is in canceled state.

| Improve this Doc View Source

StopAsync()

Stops timer execution.

Declaration
public Task<bool> StopAsync()
Returns
Type Description
Task<Boolean>

true if timer shutdown was initiated by the callback; otherwise, false.

Exceptions
Type Condition
ObjectDisposedException

The timer has been disposed.

Implements

System.IAsyncDisposable

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)
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