Thetype exposes the following members.
Tracks an external time source.
Returns what is essentially an infinite timespan.
Returns the current time relative to time the system started.
Returns the resolution of the underlying system timer.
Use of system time rather than real-time is useful in situations where events need to be timed in relative rather than absolute time. Using absolute time to measure intervals call can be problematic because system clock may be have to be periodically corrected to keep it in sync with a global time base. These corrections will cause event timers to become inaccurate.
|The DateTime instances returned by this class are useful only for measuring timespans. The Day, Month, Year properties will have no useful meaning.|
|The class is implemented such that the first time returned by the Now property will be a time value that is a minumim of one year after MinValue. This is useful in situations where programs want to schedule a periodic event for immediate triggering when the application starts by setting the last trigger time to MinValue.|
The local side clock will likely drift over time, resulting in a skew between the time returned by ExternalNow and the actual time at the external source. This skew can be limited by getting the external time and assigning it to ExternalNow more frequently.
|The time returned by ExternalNow is not guaranteed to be monotimically increasing since reported times may jump around as the bias between the local and external clocks are adjusted.|
This class is currently implemented using the Windows GetTickCount() API. This function returns the number of milliseconds since the operating system was booted with a resolution equal to the process/threading timeslice (typically 10-15 milliseconds). The actual resolution for the current machine can be obtained from Resolution.
The TickCount counter is an unsigned 32-bit value and will wrap-around every 49.7 days. The class handles this by using a GatedTimer to wake up every five minutes to check for and handle this wrap-around.
As noted above, the time value returned by Now has no relation to the actual calendar date. The first date returned after booting the computer will be approximately 1/1/0002 00:00:00, one year greater the minimum DateTime value. Infinite returns a calculated value that when added to Now will result in a date one year less then the maximum DateTime value.
These one year offsets were choosen so that applications can perform reasonable offset calculations (e.g. within background tasks) without fear of wrap-around. Since DateTime and TimeSpan span up to 10,000 years, this means that calculations will remain valid for up to 9,998 years after the computer has been started, which should be good enough for most applications.