Skip to content

Latest commit

 

History

History
91 lines (59 loc) · 6.85 KB

System.Threading.PeriodicTimerWrapper.md

File metadata and controls

91 lines (59 loc) · 6.85 KB

PeriodicTimerWrapper Class

Provides a lightweight wrapper around a System.Threading.PeriodicTimer to enable controlling the timer via a System.TimeProvider. A periodic timer enables waiting asynchronously for timer ticks.

public abstract class PeriodicTimerWrapper :
System.IDisposable

Inheritance System.Object 🡒 PeriodicTimerWrapper

Implements System.IDisposable

Remarks

This timer is intended to be used only by a single consumer at a time: only one call to WaitForNextTickAsync(CancellationToken) may be in flight at any given moment. Dispose() may be used concurrently with an active WaitForNextTickAsync(CancellationToken) to interrupt it and cause it to return false.

Methods

PeriodicTimerWrapper.~PeriodicTimerWrapper() Method

Ensures that resources are freed and other cleanup operations are performed when the garbage collector reclaims the System.Threading.PeriodicTimer object.

~PeriodicTimerWrapper();

PeriodicTimerWrapper.Dispose() Method

Stops the timer and releases associated managed resources.

public void Dispose();

Implements Dispose()

Remarks

Dispose() will cause an active wait with WaitForNextTickAsync(CancellationToken) to complete with a value of false. All subsequent WaitForNextTickAsync(CancellationToken) invocations will produce a value of false.

PeriodicTimerWrapper.Dispose(bool) Method

Dispose of the wrapped System.Threading.PeriodicTimer.

protected abstract void Dispose(bool disposing);

Parameters

disposing System.Boolean

PeriodicTimerWrapper.WaitForNextTickAsync(CancellationToken) Method

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

public abstract System.Threading.Tasks.ValueTask<bool> WaitForNextTickAsync(System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

cancellationToken System.Threading.CancellationToken

A System.Threading.CancellationToken to use to cancel the asynchronous wait. If cancellation is requested, it affects only the single wait operation; the underlying timer continues firing.

Returns

System.Threading.Tasks.ValueTask<System.Boolean>
A task that will be completed due to the timer firing, Dispose() being called to stop the timer, or cancellation being requested.

Remarks

The System.Threading.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().