On my computer the Stopwatch is returning values way too low. For example, 200 ms when I specified Thread.Sleep(1000)
. The program is supposed to wait 1 second. I a
You can use that code to fix "Stopwatch.Elapsed" method problem:
using System;
using System.Diagnostics;
namespace HQ.Util.General
{
public static class StopWatchExtension
{
public static TimeSpan ToTimeSpan(this Stopwatch stopWatch)
{
return TimeSpan.FromTicks(stopWatch.ElapsedTicks);
}
}
}
Usage:
using HQ.Util.General;
Debug.Print($"Elapsed millisec: { stopWatch.ToTimeSpan().TotalMilliseconds}");