Interface ITimeService
A time service.
public interface ITimeService
- 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.
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).
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).
DateTime DateTimeUtcNow { get; }
Property Value
MaxDelay
Gets the maximum delay interval supported by DelayAsync(TimeSpan).
TimeSpan MaxDelay { get; }
Property Value
Methods
CreateTimer(TimerCallback, object, TimeSpan, TimeSpan)
Creates a timer.
ITimer CreateTimer(TimerCallback callback, object state, TimeSpan dueTime, TimeSpan period)
Parameters
callback
TimerCallbackA delegate representing a method to be executed.
state
objectAn object containing information to be used by the callback method, or null.
dueTime
TimeSpanThe 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
TimeSpanThe 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
orperiod
is negative and not equal to Infinite, or is greater than MaxValue.
DelayAsync(TimeSpan)
Creates a task that completes after a specified time interval.
Task DelayAsync(TimeSpan delay)
Parameters
delay
TimeSpanThe 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 thanTimeSpan.FromMilliseconds(-1)
.
DelayAsync(TimeSpan, CancellationToken)
Creates a cancellable task that completes after a specified time interval.
Task DelayAsync(TimeSpan delay, CancellationToken cancellationToken)
Parameters
delay
TimeSpanThe time span to wait before completing the returned task, or
TimeSpan.FromMilliseconds(-1)
(available via InfiniteTimeSpan) to wait indefinitely.cancellationToken
CancellationTokenThe 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 thanTimeSpan.FromMilliseconds(-1)
.
StartNewStopwatch()
Initializes a new stopwatch instance, sets the elapsed time property to zero, and starts measuring elapsed time.
IStopwatch StartNewStopwatch()
Returns
- IStopwatch
A IStopwatch that has just begun measuring elapsed time.