Method RegisterAsyncTimer
RegisterAsyncTimer(IPrimeClock, TimeSpan, Func<ClockTimerCallbackContext, CancellationToken, ValueTask>, CancellationToken, object?, bool, IntervalTimerOptions?)
Registers a one-shot or repeating interval timer with an asynchronous callback that receives context and cancellation token.
public static IClockIntervalTimer RegisterAsyncTimer(this IPrimeClock clock, TimeSpan callbackTime, Func<ClockTimerCallbackContext, CancellationToken, ValueTask> callback, CancellationToken cancellationToken, object? state = null, bool repeat = false, IntervalTimerOptions? timerOptions = null)
Parameters
clockIPrimeClockcallbackTimeTimeSpanTime until the first callback.
callbackFunc<ClockTimerCallbackContext, CancellationToken, ValueTask>The async callback; receives timer context and a cancellation token.
cancellationTokenCancellationTokenToken that participates in cancelling the timer registration and is passed to the callback; use None when no external cancellation is required.
stateobjectOptional state passed to the callback via ClockTimerCallbackContext.
repeatboolIf
true, repeat usingcallbackTimeas the interval.timerOptionsIntervalTimerOptionsOptional timer options.
Returns
- IClockIntervalTimer
An IClockIntervalTimer to monitor or change the timer.
RegisterAsyncTimer(IPrimeClock, TimeSpan, Func<CancellationToken, ValueTask>, CancellationToken, bool, IntervalTimerOptions?)
Registers a one-shot or repeating interval timer with an asynchronous callback.
public static IClockIntervalTimer RegisterAsyncTimer(this IPrimeClock clock, TimeSpan callbackTime, Func<CancellationToken, ValueTask> callback, CancellationToken cancellationToken, bool repeat = false, IntervalTimerOptions? timerOptions = null)
Parameters
clockIPrimeClockcallbackTimeTimeSpanTime until the first callback.
callbackFunc<CancellationToken, ValueTask>The async callback (returns ValueTask).
cancellationTokenCancellationTokenToken that participates in cancelling the timer registration and is passed to the callback; use None when no external cancellation is required.
repeatboolIf
true, repeat usingcallbackTimeas the interval.timerOptionsIntervalTimerOptionsOptional timer options.
Returns
- IClockIntervalTimer
An IClockIntervalTimer to monitor or change the timer.
RegisterAsyncTimer(IPrimeClock, TimeSpan, TimeSpan, Func<CancellationToken, ValueTask>, CancellationToken, IntervalTimerOptions?)
Registers an interval timer with an initial delay and a separate repeat interval (async callback).
public static IClockIntervalTimer RegisterAsyncTimer(this IPrimeClock clock, TimeSpan callbackTime, TimeSpan repeatInterval, Func<CancellationToken, ValueTask> callback, CancellationToken cancellationToken, IntervalTimerOptions? timerOptions = null)
Parameters
clockIPrimeClockcallbackTimeTimeSpanTime until the first callback.
repeatIntervalTimeSpanInterval for subsequent callbacks; InfiniteTimeSpan for one-shot.
callbackFunc<CancellationToken, ValueTask>The async callback (returns ValueTask).
cancellationTokenCancellationTokenToken that participates in cancelling the timer registration and is passed to the callback; use None when no external cancellation is required.
timerOptionsIntervalTimerOptionsOptional timer options.
Returns
- IClockIntervalTimer
An IClockIntervalTimer to monitor or change the timer.