From a1955ec377c58dd85dd9cab67ef7fd9ae6b706e2 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 24 Apr 2021 20:39:05 +0200 Subject: [PATCH] Added LastUpdateTime to update-triggers --- RGB.NET.Core/Update/AbstractUpdateTrigger.cs | 6 ++++++ RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs | 6 +++++- RGB.NET.Core/Update/IUpdateTrigger.cs | 2 ++ RGB.NET.Core/Update/ManualUpdateTrigger.cs | 2 +- RGB.NET.Core/Update/TimerUpdateTrigger.cs | 2 +- 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/RGB.NET.Core/Update/AbstractUpdateTrigger.cs b/RGB.NET.Core/Update/AbstractUpdateTrigger.cs index 3d754fd..127b215 100644 --- a/RGB.NET.Core/Update/AbstractUpdateTrigger.cs +++ b/RGB.NET.Core/Update/AbstractUpdateTrigger.cs @@ -7,6 +7,12 @@ namespace RGB.NET.Core /// public abstract class AbstractUpdateTrigger : AbstractBindable, IUpdateTrigger { + #region Properties & Fields + + public abstract double LastUpdateTime { get; protected set; } + + #endregion + #region Events /// diff --git a/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs b/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs index 61e85a3..4ae41cd 100644 --- a/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs +++ b/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs @@ -53,6 +53,8 @@ namespace RGB.NET.Core } } + public override double LastUpdateTime { get; protected set; } + protected AutoResetEvent HasDataEvent { get; set; } = new(false); protected bool IsRunning { get; set; } @@ -126,9 +128,11 @@ namespace RGB.NET.Core OnUpdate(); + double lastUpdateTime = ((Stopwatch.GetTimestamp() - preUpdateTicks) / 10000.0); + LastUpdateTime = lastUpdateTime; + if (UpdateFrequency > 0) { - double lastUpdateTime = ((Stopwatch.GetTimestamp() - preUpdateTicks) / 10000.0); int sleep = (int)((UpdateFrequency * 1000.0) - lastUpdateTime); if (sleep > 0) Thread.Sleep(sleep); diff --git a/RGB.NET.Core/Update/IUpdateTrigger.cs b/RGB.NET.Core/Update/IUpdateTrigger.cs index 4d75cae..0af6d33 100644 --- a/RGB.NET.Core/Update/IUpdateTrigger.cs +++ b/RGB.NET.Core/Update/IUpdateTrigger.cs @@ -7,6 +7,8 @@ namespace RGB.NET.Core /// public interface IUpdateTrigger : IDisposable { + double LastUpdateTime { get; } + /// /// Occurs when the trigger is starting up. /// diff --git a/RGB.NET.Core/Update/ManualUpdateTrigger.cs b/RGB.NET.Core/Update/ManualUpdateTrigger.cs index 728f43e..3832570 100644 --- a/RGB.NET.Core/Update/ManualUpdateTrigger.cs +++ b/RGB.NET.Core/Update/ManualUpdateTrigger.cs @@ -22,7 +22,7 @@ namespace RGB.NET.Core /// /// Gets the time it took the last update-loop cycle to run. /// - public double LastUpdateTime { get; private set; } + public override double LastUpdateTime { get; protected set; } #endregion diff --git a/RGB.NET.Core/Update/TimerUpdateTrigger.cs b/RGB.NET.Core/Update/TimerUpdateTrigger.cs index a63c29b..e6ef02a 100644 --- a/RGB.NET.Core/Update/TimerUpdateTrigger.cs +++ b/RGB.NET.Core/Update/TimerUpdateTrigger.cs @@ -33,7 +33,7 @@ namespace RGB.NET.Core /// /// Gets the time it took the last update-loop cycle to run. /// - public double LastUpdateTime { get; private set; } + public override double LastUpdateTime { get; protected set; } #endregion