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
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.
Ensures that resources are freed and other cleanup operations are performed when the garbage collector reclaims the System.Threading.PeriodicTimer object.
~PeriodicTimerWrapper();
Stops the timer and releases associated managed resources.
public void Dispose();
Implements Dispose()
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.
Dispose of the wrapped System.Threading.PeriodicTimer.
protected abstract void Dispose(bool disposing);
disposing
System.Boolean
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));
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.
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.
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().