Table of Contents

Class DefaultTimeService

Namespace
Acuit.Pinpoint.Timing
Assembly
Acuit.Pinpoint.Timing.dll

A default implementation for ITimeService.

public class DefaultTimeService : ITimeService
Inheritance
DefaultTimeService
Implements
Inherited Members
Extension Methods

Properties

DateTimeNow

Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.

public DateTime DateTimeNow { get; }

Property Value

DateTime

DateTimeOffsetNow

Gets a DateTimeOffset object that is set to the current date and time on this computer, with the offset set to the local time's offset from Coordinated Universal Time (UTC).

public DateTimeOffset DateTimeOffsetNow { get; }

Property Value

DateTimeOffset

DateTimeUtcNow

Gets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).

public DateTime DateTimeUtcNow { get; }

Property Value

DateTime

MaxDelay

Gets the maximum delay interval supported by DelayAsync(TimeSpan).

public TimeSpan MaxDelay { get; }

Property Value

TimeSpan

Methods

CreateTimer(TimerCallback, object, TimeSpan, TimeSpan)

Creates a timer.

public ITimer CreateTimer(TimerCallback callback, object state, TimeSpan dueTime, TimeSpan period)

Parameters

callback TimerCallback

A delegate representing a method to be executed.

state object

An object containing information to be used by the callback method, or null.

dueTime TimeSpan

The amount of time to delay before the callback parameter invokes its methods. Specify InfiniteTimeSpan to prevent the timer from starting. Specify Zero to start the timer immediately.

period TimeSpan

The time interval between invocations of the methods referenced by callback. Specify InfiniteTimeSpan to disable periodic signaling.

Returns

ITimer

The timer.

Remarks

This callback will be called on a thread pool thread. Reentrancy is not prevented: if a callback is still executing for the previous occurance, the next callback will be executed on schedule on a different thread pool thread.

Exceptions

ArgumentNullException

callback is null.

ArgumentOutOfRangeException

The number of milliseconds in the value of dueTime or period is negative and not equal to Infinite, or is greater than MaxValue.

DelayAsync(TimeSpan)

Creates a task that completes after a specified time interval.

public Task DelayAsync(TimeSpan delay)

Parameters

delay TimeSpan

The time span to wait before completing the returned task, or TimeSpan.FromMilliseconds(-1) (available via InfiniteTimeSpan) to wait indefinitely.

Returns

Task

A task that represents the time delay.

Exceptions

ArgumentOutOfRangeException

delay is greater than MaxDelay or represents a negative time interval other than TimeSpan.FromMilliseconds(-1).

DelayAsync(TimeSpan, CancellationToken)

Creates a cancellable task that completes after a specified time interval.

public Task DelayAsync(TimeSpan delay, CancellationToken cancellationToken)

Parameters

delay TimeSpan

The time span to wait before completing the returned task, or TimeSpan.FromMilliseconds(-1) (available via InfiniteTimeSpan) to wait indefinitely.

cancellationToken CancellationToken

The cancellation token that will be checked prior to completing the returned task.

Returns

Task

A task that represents the time delay.

Exceptions

ArgumentOutOfRangeException

delay is greater than MaxDelay or represents a negative time interval other than TimeSpan.FromMilliseconds(-1).

StartNewStopwatch()

Initializes a new stopwatch instance, sets the elapsed time property to zero, and starts measuring elapsed time.

public IStopwatch StartNewStopwatch()

Returns

IStopwatch

A IStopwatch that has just begun measuring elapsed time.