diff --git a/RGB.NET.Core/RGBSurface.cs b/RGB.NET.Core/RGBSurface.cs index 47d78bc..18fd275 100644 --- a/RGB.NET.Core/RGBSurface.cs +++ b/RGB.NET.Core/RGBSurface.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; using System.Linq; namespace RGB.NET.Core @@ -22,7 +23,7 @@ namespace RGB.NET.Core /// public static RGBSurface Instance { get; } = new RGBSurface(); - private DateTime _lastUpdate; + private long _lastUpdateTicks; private IList _deviceProvider = new List(); private IList _devices = new List(); @@ -59,7 +60,7 @@ namespace RGB.NET.Core /// private RGBSurface() { - _lastUpdate = DateTime.Now; + _lastUpdateTicks = Stopwatch.GetTimestamp(); CheckUpdateLoop(); } diff --git a/RGB.NET.Core/RGBSurfaceDeviceEvents.cs b/RGB.NET.Core/RGBSurfaceDeviceEvents.cs index ddb9a30..36acc1b 100644 --- a/RGB.NET.Core/RGBSurfaceDeviceEvents.cs +++ b/RGB.NET.Core/RGBSurfaceDeviceEvents.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; namespace RGB.NET.Core { @@ -82,9 +83,9 @@ namespace RGB.NET.Core { try { - long lastUpdateTicks = _lastUpdate.Ticks; - _lastUpdate = DateTime.Now; - Updating?.Invoke(new UpdatingEventArgs((DateTime.Now.Ticks - lastUpdateTicks) / 10000000.0)); + long lastUpdateTicks = _lastUpdateTicks; + _lastUpdateTicks = Stopwatch.GetTimestamp(); + Updating?.Invoke(new UpdatingEventArgs((_lastUpdateTicks - lastUpdateTicks) / 10000000.0)); } catch { /* Well ... that's not my fault */ } } diff --git a/RGB.NET.Core/RGBSurfaceUpdater.cs b/RGB.NET.Core/RGBSurfaceUpdater.cs index e7a0d96..86ac31a 100644 --- a/RGB.NET.Core/RGBSurfaceUpdater.cs +++ b/RGB.NET.Core/RGBSurfaceUpdater.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Threading; using System.Threading.Tasks; @@ -86,11 +87,11 @@ namespace RGB.NET.Core { while (!_updateToken.IsCancellationRequested) { - long preUpdateTicks = DateTime.Now.Ticks; + long preUpdateTicks = Stopwatch.GetTimestamp(); Update(); - LastUpdateTime = ((DateTime.Now.Ticks - preUpdateTicks) / 10000.0); + LastUpdateTime = ((Stopwatch.GetTimestamp() - preUpdateTicks) / 10000.0); int sleep = (int)((UpdateFrequency * 1000.0) - LastUpdateTime); if (sleep > 0) Thread.Sleep(sleep);