RaspberryIO/Unosquare.RaspberryIO/Native/HighResolutionTimer.cs
2019-12-03 18:43:54 +01:00

31 lines
1002 B
C#

using System;
using System.Diagnostics;
namespace Unosquare.RaspberryIO.Native {
/// <summary>
/// Provides access to a high- esolution, time measuring device.
/// </summary>
/// <seealso cref="Stopwatch" />
public class HighResolutionTimer : Stopwatch {
/// <summary>
/// Initializes a new instance of the <see cref="HighResolutionTimer"/> class.
/// </summary>
/// <exception cref="NotSupportedException">High-resolution timer not available</exception>
public HighResolutionTimer() {
if(!IsHighResolution) {
throw new NotSupportedException("High-resolution timer not available");
}
}
/// <summary>
/// Gets the numer of microseconds per timer tick.
/// </summary>
public static Double MicrosecondsPerTick { get; } = 1000000d / Frequency;
/// <summary>
/// Gets the elapsed microseconds.
/// </summary>
public Int64 ElapsedMicroseconds => (Int64)(this.ElapsedTicks * MicrosecondsPerTick);
}
}