The AutoAdvanceBehavior type provides a way to enable and customize the automatic advance of time.
public sealed class AutoAdvanceBehavior :
System.IEquatable<TimeProviderExtensions.AutoAdvanceBehavior>
Inheritance System.Object 🡒 AutoAdvanceBehavior
Implements System.IEquatable<AutoAdvanceBehavior>
Gets or sets the amount of times timer callbacks will automatically be triggered.
Setting this to a number greater than 0
causes any active timers to have their callback invoked until they have been invoked the number of times
specified by TimerAutoTriggerCount. Before timer callbacks are invoked, time is advanced to match
the time the callback was scheduled to be invoked, just as it is if Advance(TimeSpan)
or SetUtcNow(DateTimeOffset) was manually called.
Setting this to 1
can be used to ensure all timers, e.g. those used by Task.Delay(TimeSpan, TimeProvider)
,
Task.WaitAsync(TimeSpan, TimeProvider)
, CancellationTokenSource.CancelAfter(TimeSpan)
and others
are completed immediately.
Setting this to a number larger than 1
, e.g. 10
, can be used to automatically cause a PeriodicTimer(TimeSpan, TimeProvider)
to automatically have its PeriodicTimer.WaitForNextTickAsync(CancellationToken)
async enumerable return 10
times.
public int TimerAutoTriggerCount { get; set; }
System.ArgumentOutOfRangeException
Thrown when set to a value less than zero 0
.
Set to 0
to disable auto timer callback invocation. The default value is zero 0
.
Gets or sets the amount of time by which time advances whenever the a timestamp is read via System.TimeProvider.GetTimestamp or an elapsed time is calculated with System.TimeProvider.GetElapsedTime(System.Int64).
public System.TimeSpan TimestampAdvanceAmount { get; set; }
System.ArgumentOutOfRangeException
Thrown when set to a value less than System.TimeSpan.Zero.
Set to System.TimeSpan.Zero to disable auto advance. The default value is System.TimeSpan.Zero.
Gets or sets the amount of time by which time advances whenever the clock is read via System.TimeProvider.GetUtcNow or System.TimeProvider.GetLocalNow.
public System.TimeSpan UtcNowAdvanceAmount { get; set; }
System.ArgumentOutOfRangeException
Thrown when set to a value less than System.TimeSpan.Zero.
Set to System.TimeSpan.Zero to disable auto advance. The default value is System.TimeSpan.Zero.