From c98ffd2dbf1d8081dc6bb6a719907a20eede67ec Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 3 Mar 2020 14:29:49 +0100 Subject: [PATCH] Correctly implemented Dispose for update-triggers --- RGB.NET.Core/RGBSurface.cs | 4 ++++ RGB.NET.Core/Update/AbstractUpdateTrigger.cs | 5 ++--- RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs | 3 +++ RGB.NET.Core/Update/TimerUpdateTrigger.cs | 3 +++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/RGB.NET.Core/RGBSurface.cs b/RGB.NET.Core/RGBSurface.cs index 7ba3183..9528f78 100644 --- a/RGB.NET.Core/RGBSurface.cs +++ b/RGB.NET.Core/RGBSurface.cs @@ -139,6 +139,10 @@ namespace RGB.NET.Core try { deviceProvider.Dispose(); } catch { /* We do what we can */ } + foreach (IUpdateTrigger updateTrigger in _updateTriggers) + try { updateTrigger.Dispose(); } + catch { /* We do what we can */ } + _ledGroups.Clear(); _devices = null; _deviceProvider = null; diff --git a/RGB.NET.Core/Update/AbstractUpdateTrigger.cs b/RGB.NET.Core/Update/AbstractUpdateTrigger.cs index 3ac5d46..e311037 100644 --- a/RGB.NET.Core/Update/AbstractUpdateTrigger.cs +++ b/RGB.NET.Core/Update/AbstractUpdateTrigger.cs @@ -5,7 +5,7 @@ namespace RGB.NET.Core /// /// Represents a generic update trigger. /// - public class AbstractUpdateTrigger : AbstractBindable, IUpdateTrigger + public abstract class AbstractUpdateTrigger : AbstractBindable, IUpdateTrigger { #region Events @@ -31,8 +31,7 @@ namespace RGB.NET.Core protected virtual void OnUpdate(CustomUpdateData updateData = null) => Update?.Invoke(this, updateData); /// - public virtual void Dispose() - { } + public abstract void Dispose(); #endregion } diff --git a/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs b/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs index 04cfb92..8f4beba 100644 --- a/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs +++ b/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs @@ -144,6 +144,9 @@ namespace RGB.NET.Core UpdateFrequency = UpdateRateHardLimit; } + /// + public override void Dispose() => Stop(); + #endregion } } diff --git a/RGB.NET.Core/Update/TimerUpdateTrigger.cs b/RGB.NET.Core/Update/TimerUpdateTrigger.cs index 23eaa96..0171ffb 100644 --- a/RGB.NET.Core/Update/TimerUpdateTrigger.cs +++ b/RGB.NET.Core/Update/TimerUpdateTrigger.cs @@ -106,6 +106,9 @@ namespace RGB.NET.Core } } + /// + public override void Dispose() => Stop(); + #endregion } }