A implementation of a System.Threading.ITimer whose callbacks are scheduled via a ManualTimeProvider.
public class ManualTimer :
System.IDisposable,
System.IAsyncDisposable
Inheritance System.Object 🡒 System.Threading.ITimer 🡒 ManualTimer
Implements System.IDisposable, System.IAsyncDisposable
Creates an instance of the ManualTimer. No callbacks are scheduled during construction. Call Change(TimeSpan, TimeSpan) to schedule invocations of callback using the provided timeProvider.
protected internal ManualTimer(System.Threading.TimerCallback callback, object? state, TimeProviderExtensions.ManualTimeProvider timeProvider);
callback
System.Threading.TimerCallback
A delegate representing a method to be executed when the timer fires. The method specified for callback should be reentrant, as it may be invoked simultaneously on two threads if the timer fires again before or while a previous callback is still being handled.
state
System.Object
An object to be passed to the callback. This may be null.
timeProvider
ManualTimeProvider
The ManualTimeProvider which is used to schedule invocations of the callback with.
Gets the number of times a timer's callback has been invoked.
public int CallbackInvokeCount { get; }
Gets the next time the timer callback will be invoked, or null if the timer is inactive.
public System.Nullable<System.DateTimeOffset> CallbackTime { get; }
System.Nullable<System.DateTimeOffset>
Gets the System.TimeSpan representing the amount of time to delay before invoking the callback method specified when the System.Threading.ITimer was constructed.
public System.TimeSpan DueTime { get; set; }
Gets whether the timer is currently active, i.e. has a future callback invocation scheduled.
public bool IsActive { get; }
When IsActive returns true, CallbackTime is not null.
Gets the time interval between invocations of the callback method specified when the Timer was constructed. If set to System.Threading.Timeout.InfiniteTimeSpan periodic signaling is disabled.
public System.TimeSpan Period { get; set; }
The finalizer exists in case the timer is not disposed explicitly by the user.
~ManualTimer();
Changes the start time and the interval between method invocations for a timer, using System.TimeSpan values to measure time intervals.
public virtual bool Change(System.TimeSpan dueTime, System.TimeSpan period);
dueTime
System.TimeSpan
A System.TimeSpan representing the amount of time to delay before invoking the callback method specified when the System.Threading.ITimer was constructed. Specify System.Threading.Timeout.InfiniteTimeSpan to prevent the timer from restarting. Specify System.TimeSpan.Zero to restart the timer immediately.
period
System.TimeSpan
The time interval between invocations of the callback method specified when the Timer was constructed. Specify System.Threading.Timeout.InfiniteTimeSpan to disable periodic signaling.
System.Boolean
true if the timer was successfully updated; otherwise, false.
System.ArgumentOutOfRangeException
The dueTime or period parameter, in milliseconds, is less than -1 or greater than 4294967294.
It is the responsibility of the implementer of the ITimer interface to ensure thread safety.
Disposes of the ManualTimer and removes any scheduled callbacks from the ManualTimeProvider.
public void Dispose();
Implements Dispose()
Disposes of the ManualTimer and removes any scheduled callbacks from the ManualTimeProvider.
protected virtual void Dispose(bool disposing);
disposing
System.Boolean
If this method is overridden, it should always be called by the overriding method.
Disposes of the ManualTimer and removes any scheduled callbacks from the ManualTimeProvider.
public System.Threading.Tasks.ValueTask DisposeAsync();
Implements DisposeAsync()
System.Threading.Tasks.ValueTask
Returns a string that represents the current object.
public override string ToString();
System.String
A string that represents the current object.