Method RegisterAsyncTimer
RegisterAsyncTimer(IPrimeClock, Duration, 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, Duration callbackTime, Func<CancellationToken, ValueTask> callback, CancellationToken cancellationToken, bool repeat = false, IntervalTimerOptions? timerOptions = null)
Parameters
clockIPrimeClockThe clock on which to register the timer.
callbackTimeDurationDuration 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, Duration, 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, Duration callbackTime, Func<ClockTimerCallbackContext, CancellationToken, ValueTask> callback, CancellationToken cancellationToken, object? state = null, bool repeat = false, IntervalTimerOptions? timerOptions = null)
Parameters
clockIPrimeClockThe clock on which to register the timer.
callbackTimeDurationDuration 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, Duration, Duration, 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, Duration callbackTime, Duration repeatInterval, Func<CancellationToken, ValueTask> callback, CancellationToken cancellationToken, IntervalTimerOptions? timerOptions = null)
Parameters
clockIPrimeClockThe clock on which to register the timer.
callbackTimeDurationDuration until the first callback.
repeatIntervalDurationInterval for subsequent callbacks; use a non-positive duration 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.