Class DefaultTimeService
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
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
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
MaxDelay
Gets the maximum delay interval supported by DelayAsync(TimeSpan).
public TimeSpan MaxDelay { get; }
Property Value
Methods
CreateTimer(TimerCallback, object, TimeSpan, TimeSpan)
Creates a timer.
public ITimer CreateTimer(TimerCallback callback, object state, TimeSpan dueTime, TimeSpan period)
Parameters
callbackTimerCallbackA delegate representing a method to be executed.
stateobjectAn object containing information to be used by the callback method, or null.
dueTimeTimeSpanThe 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.
periodTimeSpanThe 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
callbackis null.- ArgumentOutOfRangeException
The number of milliseconds in the value of
dueTimeorperiodis 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
delayTimeSpanThe 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
delayis greater than MaxDelay or represents a negative time interval other thanTimeSpan.FromMilliseconds(-1).
DelayAsync(TimeSpan, CancellationToken)
Creates a cancellable task that completes after a specified time interval.
public Task DelayAsync(TimeSpan delay, CancellationToken cancellationToken)
Parameters
delayTimeSpanThe time span to wait before completing the returned task, or
TimeSpan.FromMilliseconds(-1)(available via InfiniteTimeSpan) to wait indefinitely.cancellationTokenCancellationTokenThe cancellation token that will be checked prior to completing the returned task.
Returns
- Task
A task that represents the time delay.
Exceptions
- ArgumentOutOfRangeException
delayis greater than MaxDelay or represents a negative time interval other thanTimeSpan.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.