namespace SmartCoalApplication.SystemLayer
{
///
/// Methods for keeping track of time in a high precision manner.
///
///
/// This class provides precision and accuracy of 1 millisecond.
///
public sealed class Timing
{
private ulong countsPerMs;
private double countsPerMsDouble;
private ulong birthTick;
///
/// The number of milliseconds that elapsed between system startup
/// and creation of this instance of Timing.
///
public ulong BirthTick
{
get
{
return birthTick;
}
}
///
/// Returns the number of milliseconds that have elapsed since
/// system startup.
///
public ulong GetTickCount()
{
ulong tick;
SafeNativeMethods.QueryPerformanceCounter(out tick);
return tick / countsPerMs;
}
///
/// Returns the number of milliseconds that have elapsed since
/// system startup.
///
public double GetTickCountDouble()
{
ulong tick;
SafeNativeMethods.QueryPerformanceCounter(out tick);
return (double)tick / countsPerMsDouble;
}
///
/// Constructs an instance of the Timing class.
///
public Timing()
{
ulong frequency;
if (!SafeNativeMethods.QueryPerformanceFrequency(out frequency))
{
NativeMethods.ThrowOnWin32Error("QueryPerformanceFrequency returned false");
}
countsPerMs = frequency / 1000;
countsPerMsDouble = (double)frequency / 1000.0;
birthTick = GetTickCount();
}
}
}