Class AsyncTimer
Represents asynchronous timer.
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class AsyncTimer : Disposable
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 SourceAsyncTimer(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. |
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. |
Properties
| Improve this Doc View SourceIsRunning
Indicates that this timer is running.
Declaration
public bool IsRunning { get; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
| Improve this Doc View SourceDispose(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 |
Start(TimeSpan, CancellationToken)
Starts the timer.
Declaration
public bool Start(TimeSpan period, CancellationToken token = null)
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. |
Start(TimeSpan, TimeSpan, CancellationToken)
Starts the timer.
Declaration
public bool Start(TimeSpan dueTime, TimeSpan period, CancellationToken token = null)
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. |
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. |