Skip to content

Latest commit

 

History

History
224 lines (139 loc) · 13.4 KB

TimeProviderExtensions.ManualTimer.md

File metadata and controls

224 lines (139 loc) · 13.4 KB

ManualTimer Class

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

Constructors

ManualTimer(TimerCallback, object, ManualTimeProvider) Constructor

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);

Parameters

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.

Properties

ManualTimer.CallbackInvokeCount Property

Gets the number of times a timer's callback has been invoked.

public int CallbackInvokeCount { get; }

Property Value

System.Int32

ManualTimer.CallbackTime Property

Gets the next time the timer callback will be invoked, or null if the timer is inactive.

public System.Nullable<System.DateTimeOffset> CallbackTime { get; }

Property Value

System.Nullable<System.DateTimeOffset>

ManualTimer.DueTime Property

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; }

Property Value

System.TimeSpan

ManualTimer.IsActive Property

Gets whether the timer is currently active, i.e. has a future callback invocation scheduled.

public bool IsActive { get; }

Property Value

System.Boolean

Remarks

When IsActive returns true, CallbackTime is not null.

ManualTimer.Period Property

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; }

Property Value

System.TimeSpan

Methods

ManualTimer.~ManualTimer() Method

The finalizer exists in case the timer is not disposed explicitly by the user.

~ManualTimer();

ManualTimer.Change(TimeSpan, TimeSpan) Method

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);

Parameters

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.

Returns

System.Boolean
true if the timer was successfully updated; otherwise, false.

Exceptions

System.ArgumentOutOfRangeException
The dueTime or period parameter, in milliseconds, is less than -1 or greater than 4294967294.

Remarks

It is the responsibility of the implementer of the ITimer interface to ensure thread safety.

ManualTimer.Dispose() Method

Disposes of the ManualTimer and removes any scheduled callbacks from the ManualTimeProvider.

public void Dispose();

Implements Dispose()

ManualTimer.Dispose(bool) Method

Disposes of the ManualTimer and removes any scheduled callbacks from the ManualTimeProvider.

protected virtual void Dispose(bool disposing);

Parameters

disposing System.Boolean

Remarks

If this method is overridden, it should always be called by the overriding method.

ManualTimer.DisposeAsync() Method

Disposes of the ManualTimer and removes any scheduled callbacks from the ManualTimeProvider.

public System.Threading.Tasks.ValueTask DisposeAsync();

Implements DisposeAsync()

Returns

System.Threading.Tasks.ValueTask

ManualTimer.ToString() Method

Returns a string that represents the current object.

public override string ToString();

Returns

System.String
A string that represents the current object.