mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
Changed the update-loop to be able to use the high-resolution-timer
This commit is contained in:
parent
9cfd17e1bc
commit
87211dab69
@ -4,6 +4,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace RGB.NET.Core
|
namespace RGB.NET.Core
|
||||||
@ -22,7 +23,7 @@ namespace RGB.NET.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static RGBSurface Instance { get; } = new RGBSurface();
|
public static RGBSurface Instance { get; } = new RGBSurface();
|
||||||
|
|
||||||
private DateTime _lastUpdate;
|
private long _lastUpdateTicks;
|
||||||
|
|
||||||
private IList<IRGBDeviceProvider> _deviceProvider = new List<IRGBDeviceProvider>();
|
private IList<IRGBDeviceProvider> _deviceProvider = new List<IRGBDeviceProvider>();
|
||||||
private IList<IRGBDevice> _devices = new List<IRGBDevice>();
|
private IList<IRGBDevice> _devices = new List<IRGBDevice>();
|
||||||
@ -59,7 +60,7 @@ namespace RGB.NET.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private RGBSurface()
|
private RGBSurface()
|
||||||
{
|
{
|
||||||
_lastUpdate = DateTime.Now;
|
_lastUpdateTicks = Stopwatch.GetTimestamp();
|
||||||
|
|
||||||
CheckUpdateLoop();
|
CheckUpdateLoop();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace RGB.NET.Core
|
namespace RGB.NET.Core
|
||||||
{
|
{
|
||||||
@ -82,9 +83,9 @@ namespace RGB.NET.Core
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
long lastUpdateTicks = _lastUpdate.Ticks;
|
long lastUpdateTicks = _lastUpdateTicks;
|
||||||
_lastUpdate = DateTime.Now;
|
_lastUpdateTicks = Stopwatch.GetTimestamp();
|
||||||
Updating?.Invoke(new UpdatingEventArgs((DateTime.Now.Ticks - lastUpdateTicks) / 10000000.0));
|
Updating?.Invoke(new UpdatingEventArgs((_lastUpdateTicks - lastUpdateTicks) / 10000000.0));
|
||||||
}
|
}
|
||||||
catch { /* Well ... that's not my fault */ }
|
catch { /* Well ... that's not my fault */ }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -86,11 +87,11 @@ namespace RGB.NET.Core
|
|||||||
{
|
{
|
||||||
while (!_updateToken.IsCancellationRequested)
|
while (!_updateToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
long preUpdateTicks = DateTime.Now.Ticks;
|
long preUpdateTicks = Stopwatch.GetTimestamp();
|
||||||
|
|
||||||
Update();
|
Update();
|
||||||
|
|
||||||
LastUpdateTime = ((DateTime.Now.Ticks - preUpdateTicks) / 10000.0);
|
LastUpdateTime = ((Stopwatch.GetTimestamp() - preUpdateTicks) / 10000.0);
|
||||||
int sleep = (int)((UpdateFrequency * 1000.0) - LastUpdateTime);
|
int sleep = (int)((UpdateFrequency * 1000.0) - LastUpdateTime);
|
||||||
if (sleep > 0)
|
if (sleep > 0)
|
||||||
Thread.Sleep(sleep);
|
Thread.Sleep(sleep);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user