1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-12 17:48:31 +00:00

Changed the update-loop to be able to use the high-resolution-timer

This commit is contained in:
Darth Affe 2018-03-17 10:50:32 +01:00
parent 9cfd17e1bc
commit 87211dab69
3 changed files with 10 additions and 7 deletions

View File

@ -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
/// </summary>
public static RGBSurface Instance { get; } = new RGBSurface();
private DateTime _lastUpdate;
private long _lastUpdateTicks;
private IList<IRGBDeviceProvider> _deviceProvider = new List<IRGBDeviceProvider>();
private IList<IRGBDevice> _devices = new List<IRGBDevice>();
@ -59,7 +60,7 @@ namespace RGB.NET.Core
/// </summary>
private RGBSurface()
{
_lastUpdate = DateTime.Now;
_lastUpdateTicks = Stopwatch.GetTimestamp();
CheckUpdateLoop();
}

View File

@ -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 */ }
}

View File

@ -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);