Edit

Share via


PeriodicTimer.WaitForNextTickAsync(CancellationToken) Method

Definition

Waits for the next tick of the timer, or for the timer to be stopped.

public System.Threading.Tasks.ValueTask<bool> WaitForNextTickAsync (System.Threading.CancellationToken cancellationToken = default);
member this.WaitForNextTickAsync : System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<bool>
Public Function WaitForNextTickAsync (Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Boolean)

Parameters

cancellationToken
CancellationToken

A CancellationToken for cancelling the asynchronous wait. If cancellation is requested, it affects only the single wait operation; the underlying timer continues firing.

Returns

A task that will be completed due to the timer firing, Dispose() being called to stop the timer, or cancellation being requested.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

The PeriodicTimer behaves like an auto-reset event, in that multiple ticks are coalesced into a single tick if they occur between calls to WaitForNextTickAsync(CancellationToken). Similarly, a call to Dispose() will void any tick not yet consumed. WaitForNextTickAsync(CancellationToken) may only be used by one consumer at a time, and may be used concurrently with a single call to Dispose().

Applies to