C# Class GSF.PrecisionTimer

Represents a high-resolution timer and timestamp class.

For standard deployments, implementation is based on the Windows multimedia timer. For mono deployments, implementation uses a basic timer for compatibility - this should have ~10ms of resolution when used on standard Linux systems.

Future mono deployments may want to consider an implementation that uses OS specific timers: For Windows use of non-Mono style implementation below should be sufficient. For Linux see http://www.ittc.ku.edu/utime/ as an example. Implememtation might depend on a platform specific P/Invokable wrapper DLL that exposed the same methods on Windows and Linux for consumption from .NET but used the specific precision timer implementations mentioned above. See the following for Mono interop details: http://www.mono-project.com/Interop_with_Native_Libraries

Inheritance: IDisposable
Mostrar archivo Open project: GridProtectionAlliance/gsf

Public Methods

Method Description
ClearMinimumTimerResolution ( int period ) : void

Clears a previously set minimum timer resolution established using SetMinimumTimerResolution.

Call this function immediately after you are finished using the PrecisionTimer. You must match each call to SetMinimumTimerResolution with a call to ClearMinimumTimerResolution, specifying the same minimum resolution period in both calls. An application can make multiple SetMinimumTimerResolution calls as long as each call is matched with a call to ClearMinimumTimerResolution.

This method is currently ignored under Mono deployments.

Dispose ( ) : void

Releases all the resources used by the PrecisionTimer object.

PrecisionTimer ( ) : System

Initializes a new instance of the PrecisionTimer class.

SetMinimumTimerResolution ( int period ) : void

Requests a minimum resolution for periodic timers such as the PrecisionTimer.

Call this function immediately before using the PrecisionTimer and call ClearMinimumTimerResolution immediately after you are finished using the PrecisionTimer. You must match each call to SetMinimumTimerResolution with a call to ClearMinimumTimerResolution specifying the same minimum resolution period in both calls. An application can make multiple ClearMinimumTimerResolution calls as long as each call is matched with a call to ClearMinimumTimerResolution. This function affects a global Windows setting. Windows uses the lowest value (that is, highest resolution) requested by any process. Setting a higher resolution can improve the accuracy of time-out intervals in wait functions. However, it can also reduce overall system performance, because the thread scheduler switches tasks more often. High resolutions can also prevent the CPU power management system from entering power-saving modes. See timeBeginPeriod Windows API for more information.

This method is currently ignored under Mono deployments.

Start ( ) : void

Starts the PrecisionTimer.

Start ( EventArgs userArgs ) : void

Starts the PrecisionTimer with the specified EventArgs.

Protected Methods

Method Description
Dispose ( bool disposing ) : void

Releases the unmanaged resources used by the PrecisionTimer object and optionally releases the managed resources.

Private Methods

Method Description
Stop ( ) : void
TimerEventCallback ( int id, int msg, int user, int param1, int param2 ) : void
m_timer_Elapsed ( object sender, System.Timers.ElapsedEventArgs e ) : void
timeBeginPeriod ( int period ) : int
timeEndPeriod ( int period ) : int
timeGetDevCaps ( TimerCapabilities &caps, int sizeOfTimerCaps ) : int
timeKillEvent ( int id ) : int
timeSetEvent ( int delay, int resolution, TimerProc proc, IntPtr user, TimerMode mode ) : int

Method Details

ClearMinimumTimerResolution() public static method

Clears a previously set minimum timer resolution established using SetMinimumTimerResolution.

Call this function immediately after you are finished using the PrecisionTimer. You must match each call to SetMinimumTimerResolution with a call to ClearMinimumTimerResolution, specifying the same minimum resolution period in both calls. An application can make multiple SetMinimumTimerResolution calls as long as each call is matched with a call to ClearMinimumTimerResolution.

This method is currently ignored under Mono deployments.

public static ClearMinimumTimerResolution ( int period ) : void
period int /// Minimum timer resolution specified in the previous call to the function. ///
return void

Dispose() public method

Releases all the resources used by the PrecisionTimer object.
public Dispose ( ) : void
return void

Dispose() protected method

Releases the unmanaged resources used by the PrecisionTimer object and optionally releases the managed resources.
protected Dispose ( bool disposing ) : void
disposing bool true to release both managed and unmanaged resources; false to release only unmanaged resources.
return void

PrecisionTimer() public method

Initializes a new instance of the PrecisionTimer class.
public PrecisionTimer ( ) : System
return System

SetMinimumTimerResolution() public static method

Requests a minimum resolution for periodic timers such as the PrecisionTimer.

Call this function immediately before using the PrecisionTimer and call ClearMinimumTimerResolution immediately after you are finished using the PrecisionTimer. You must match each call to SetMinimumTimerResolution with a call to ClearMinimumTimerResolution specifying the same minimum resolution period in both calls. An application can make multiple ClearMinimumTimerResolution calls as long as each call is matched with a call to ClearMinimumTimerResolution. This function affects a global Windows setting. Windows uses the lowest value (that is, highest resolution) requested by any process. Setting a higher resolution can improve the accuracy of time-out intervals in wait functions. However, it can also reduce overall system performance, because the thread scheduler switches tasks more often. High resolutions can also prevent the CPU power management system from entering power-saving modes. See timeBeginPeriod Windows API for more information.

This method is currently ignored under Mono deployments.

public static SetMinimumTimerResolution ( int period ) : void
period int /// Minimum timer resolution, in milliseconds, for the application. A lower value specifies a higher (more accurate) resolution. ///
return void

Start() public method

Starts the PrecisionTimer.
/// The timer has already been disposed. /// /// The timer failed to start. ///
public Start ( ) : void
return void

Start() public method

Starts the PrecisionTimer with the specified EventArgs.
/// The timer has already been disposed. /// /// The timer failed to start. ///
public Start ( EventArgs userArgs ) : void
userArgs System.EventArgs User defined event arguments to pass into raised event.
return void