/// <summary> /// This gives an accurate estimate of DateTime from ticks over shorter intervals, it won't be accurate over really long intervals though /// </summary> DateTime PerfCounterRawDateTime() { long result; Startwatch.QueryPerformanceCounter(out result); return(DateTime.Now.AddSeconds(-result / Stopwatch.Frequency)); }
/// <summary> /// Stop time tracking on the Startwatch, allowing for representation of a time period. /// </summary> /// <returns>true if the watch was running before the call, false if it was already stopped</returns> public bool Stop() { if (_stopTimestamp.Value == 0) { Startwatch.QueryPerformanceCounter(out _stopTimestamp.Value); return(true); } return(false); }
/// <summary> /// Initialize new Startwatch from System.Diagnostics.Stopwatch, /// if the System.Diagnostics.Stopwatch is actively running then the Startwatch will be running and have the same initial duration /// if the System.Diagnostics.Stopwatch is stopped then the Startwatch will be stopped /// the Startwatch will not be synchronized to the System.Diagnostics.Stopwatch in any way after it is created /// </summary> public static Startwatch FromStopwatch(Stopwatch watch) { if (watch.IsRunning) { long result; Startwatch.QueryPerformanceCounter(out result); return(new Startwatch(result - watch.ElapsedTicks)); } else { return(new Startwatch(0, watch.ElapsedTicks)); } }
/// <summary> /// Create a started stopwatch /// </summary> public Startwatch() { _stopTimestamp = new RefTimestamp(); _startTimestamp = new RefTimestamp(); Startwatch.QueryPerformanceCounter(out _startTimestamp.Value); }