Class GorgonTimerMultimedia
An implementation of the IGorgonTimer interface.
Implements
Inherited Members
Namespace: Gorgon.Timing
Assembly: Gorgon.Windows.dll
Syntax
public sealed class GorgonTimerMultimedia : IGorgonTimer
Remarks
This implementation uses the Windows Multimedia timer. It fairly stable across all hardware and provides measurement of time down to 1 millisecond.
caution
Known issues
There are a few caveats when using this timer:- This timer wraps around to 0 every 2^32 milliseconds (~49.71 days), and can cause issues in code relying on this type of timer. Gorgon will do its best to ensure this is not a problem.
- It has a default precision of 5 milliseconds, but Gorgon will attempt to change the resolution to 1 millisecond when using the GorgonApplication class.
Properties
| Edit this page View SourceDays
Property to return the number of days elapsed since the timer was started.
Declaration
public double Days { get; }
Property Value
Type | Description |
---|---|
double |
Hours
Property to return the number of hours elapsed since the timer was started.
Declaration
public double Hours { get; }
Property Value
Type | Description |
---|---|
double |
IsHighResolution
Property to return whether this timer has a resolution of less than 1 millisecond or not.
Declaration
public bool IsHighResolution { get; }
Property Value
Type | Description |
---|---|
bool |
Microseconds
Property to return the number of microseconds elapsed since the timer was started.
Declaration
public double Microseconds { get; }
Property Value
Type | Description |
---|---|
double |
Remarks
For this type of timer, this value is pretty much meaningless as the best precision of the timer is 1 millisecond at best (assuming BeginTiming(int) was called).
Milliseconds
Property to return the number of milliseconds elapsed since the timer was started.
Declaration
public double Milliseconds { get; }
Property Value
Type | Description |
---|---|
double |
Minutes
Property to return the number of minutes elapsed since the timer was started.
Declaration
public double Minutes { get; }
Property Value
Type | Description |
---|---|
double |
Seconds
Property to return the number of seconds elapsed since the timer was started.
Declaration
public double Seconds { get; }
Property Value
Type | Description |
---|---|
double |
Ticks
Property to return the number of ticks since the timer was started.
Declaration
public long Ticks { get; }
Property Value
Type | Description |
---|---|
long |
Methods
| Edit this page View SourceBeginTiming(int)
Function to set the timing period for the timer.
Declaration
public static void BeginTiming(int period = 1)
Parameters
Type | Name | Description |
---|---|---|
int | period | [Optional] Minimum timer resolution, in milliseconds, for the application or device driver. A lower value specifies a higher (more accurate) resolution.. |
Remarks
This will set the timing period for calls to the Win32 timeGetTime API function so that the resolution for the timer can be adjusted for maximum performance.
Calls to this method must be paired with the EndTiming() static method, otherwise the system will be left in a state where the task scheduler switches tasks more often and the power saving may not trigger properly.
Exceptions
Type | Condition |
---|---|
Win32Exception | Thrown when the |
EndTiming()
Function to end the timing period for the timer.
Declaration
public static void EndTiming()
Remarks
This will end the current timing period for calls to the Win32 timeGetTime API function.
Calls to this method must be paired with the BeginTiming(int) static method, otherwise the system will be left in a state where the task scheduler switches tasks more often and the power saving may not trigger properly. If BeginTiming(int) was never called, then this method will do nothing.
Exceptions
Type | Condition |
---|---|
Win32Exception | Thrown when the last known period value is out of range. |
Reset()
Function to reset the timer.
Declaration
public void Reset()
Exceptions
Type | Condition |
---|---|
Win32Exception | Thrown when timer information cannot be retrieved from the operating system. |