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

Fixed some code issues (dispose finalizers)

This commit is contained in:
Darth Affe 2023-02-10 19:23:48 +01:00
parent 180b0e4538
commit d6aed5c5a2
17 changed files with 47 additions and 10 deletions

View File

@ -22,11 +22,7 @@ public sealed class DefaultColorBehavior : IColorBehavior
/// <param name="color">The color to test.</param>
/// <param name="obj">The object to test.</param>
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Color" /> equivalent to this <see cref="Color" />; otherwise, <c>false</c>.</returns>
public bool Equals(in Color color, object? obj)
{
if (obj is not Color color2) return false;
return Equals(color, color2);
}
public bool Equals(in Color color, object? obj) => obj is Color color2 && Equals(color, color2);
/// <summary>
/// Tests whether the specified object is a <see cref="Color" /> and is equivalent to this <see cref="Color" />.

View File

@ -2,6 +2,7 @@
// ReSharper disable UnusedMember.Global
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
@ -160,6 +161,8 @@ public abstract class AbstractRGBDevice<TDeviceInfo> : Placeable, IRGBDevice<TDe
try { LedMapping.Clear(); } catch { /* this really shouldn't happen */ }
IdGenerator.ResetCounter(GetType().Assembly);
GC.SuppressFinalize(this);
}
/// <summary>

View File

@ -1,5 +1,6 @@
// ReSharper disable MemberCanBePrivate.Global
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
@ -178,7 +179,12 @@ public class DeviceUpdateTrigger : AbstractUpdateTrigger, IDeviceUpdateTrigger
}
/// <inheritdoc />
public override void Dispose() => Stop();
public override void Dispose()
{
Stop();
GC.SuppressFinalize(this);
}
#endregion
}

View File

@ -100,6 +100,8 @@ public class CoolerMasterDeviceProvider : AbstractRGBDeviceProvider
try { _CoolerMasterSDK.Reload(); }
catch { /* Unlucky.. */ }
GC.SuppressFinalize(this);
}
#endregion

View File

@ -33,6 +33,8 @@ public abstract class CoolerMasterRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDe
_CoolerMasterSDK.EnableLedControl(false, DeviceInfo.DeviceIndex);
base.Dispose();
GC.SuppressFinalize(this);
}
#endregion

View File

@ -71,6 +71,8 @@ public class DebugDeviceProvider : AbstractRGBDeviceProvider
base.Dispose();
_fakeDeviceDefinitions.Clear();
GC.SuppressFinalize(this);
}
#endregion

View File

@ -104,6 +104,8 @@ public class MsiDeviceProvider : AbstractRGBDeviceProvider
try { _MsiSDK.UnloadMsiSDK(); }
catch { /* at least we tried */ }
GC.SuppressFinalize(this);
}
#endregion

View File

@ -53,6 +53,7 @@
<ItemGroup>
<Content Include="..\Resources\icon.png" Link="icon.png" Pack="true" PackagePath="\" />
<None Include="..\.editorconfig" Link=".editorconfig" />
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>

View File

@ -49,6 +49,8 @@ public abstract class NovationRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDevice
Reset();
base.Dispose();
GC.SuppressFinalize(this);
}
#endregion

View File

@ -35,7 +35,7 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
public bool ForceAddAllDevices { get; set; } = false;
/// <summary>
/// Defines which device types will be separated by zones. Defaults to <see cref="RGBDeviceType.LedStripe" /> | <see cref="RGBDeviceType.Mainboard" | <see cref="RGBDeviceType.Speaker" />.
/// Defines which device types will be separated by zones. Defaults to <see cref="RGBDeviceType.LedStripe" /> | <see cref="RGBDeviceType.Mainboard"/> | <see cref="RGBDeviceType.Speaker" />.
/// </summary>
public RGBDeviceType PerZoneDeviceFlag { get; } = RGBDeviceType.LedStripe | RGBDeviceType.Mainboard | RGBDeviceType.Speaker;
@ -141,6 +141,8 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
_clients.Clear();
DeviceDefinitions.Clear();
Devices = Enumerable.Empty<IRGBDevice>();
GC.SuppressFinalize(this);
}
#endregion
}

View File

@ -301,6 +301,8 @@ public class RazerDeviceProvider : AbstractRGBDeviceProvider
// DarthAffe 03.03.2020: Fails with an access-violation - verify if an unload is already triggered by uninit
//try { _RazerSDK.UnloadRazerSDK(); }
//catch { /* at least we tried */ }
GC.SuppressFinalize(this);
}
#endregion

View File

@ -137,6 +137,8 @@ public class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider
try { SteelSeriesSDK.Dispose(); }
catch { /* shit happens */ }
GC.SuppressFinalize(this);
}
#endregion

View File

@ -1,4 +1,5 @@
using System.IO.Ports;
using System;
using System.IO.Ports;
namespace RGB.NET.Devices.WS281X;
@ -61,7 +62,12 @@ public class SerialPortConnection : ISerialConnection
public void WriteLine(string line) => SerialPort.WriteLine(line);
/// <inheritdoc />
public void Dispose() => SerialPort.Dispose();
public void Dispose()
{
SerialPort.Dispose();
GC.SuppressFinalize(this);
}
#endregion
}

View File

@ -171,6 +171,8 @@ public class NodeMCUWS2812USBUpdateQueue : UpdateQueue
ResetDevice();
_httpClient.Dispose();
}
GC.SuppressFinalize(this);
}
private string GetUrl(string path) => $"http://{_hostname}/{path}";

View File

@ -75,6 +75,8 @@ public class WS281XDeviceProvider : AbstractRGBDeviceProvider
base.Dispose();
DeviceDefinitions.Clear();
GC.SuppressFinalize(this);
}
#endregion

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Generic;
using RGB.NET.Devices.Wooting.Native;
@ -55,6 +56,8 @@ public class WootingKeyboardRGBDevice : WootingRGBDevice<WootingKeyboardRGBDevic
_WootingSDK.Reset();
base.Dispose();
GC.SuppressFinalize(this);
}
#endregion

View File

@ -102,6 +102,8 @@ public class WootingDeviceProvider : AbstractRGBDeviceProvider
try { _WootingSDK.UnloadWootingSDK(); }
catch { /* at least we tried */ }
}
GC.SuppressFinalize(this);
}
#endregion