diff --git a/RGB.NET.Core/Decorators/AbstractDecorateable.cs b/RGB.NET.Core/Decorators/AbstractDecorateable.cs index 50602ae..1120bc4 100644 --- a/RGB.NET.Core/Decorators/AbstractDecorateable.cs +++ b/RGB.NET.Core/Decorators/AbstractDecorateable.cs @@ -14,7 +14,7 @@ namespace RGB.NET.Core private readonly List _decorators = new(); /// - public IReadOnlyCollection Decorators { get; } + public IReadOnlyList Decorators { get; } #endregion diff --git a/RGB.NET.Core/Decorators/IDecoratable.cs b/RGB.NET.Core/Decorators/IDecoratable.cs index 2892638..ae8def2 100644 --- a/RGB.NET.Core/Decorators/IDecoratable.cs +++ b/RGB.NET.Core/Decorators/IDecoratable.cs @@ -20,7 +20,7 @@ namespace RGB.NET.Core /// /// Gets a readonly-list of all attached to this . /// - IReadOnlyCollection Decorators { get; } + IReadOnlyList Decorators { get; } /// /// Adds an to the . diff --git a/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs b/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs index 81ac6f2..6b4ee57 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs @@ -30,7 +30,7 @@ namespace RGB.NET.Core protected Dictionary UpdateTriggerMapping { get; } = new(); /// - public ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers => new(UpdateTriggerMapping.Select(x => (x.Key, x.Value)).ToList()); + public IReadOnlyList<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers => new ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)>(UpdateTriggerMapping.Select(x => (x.Key, x.Value)).ToList()); #endregion diff --git a/RGB.NET.Core/Devices/IRGBDeviceProvider.cs b/RGB.NET.Core/Devices/IRGBDeviceProvider.cs index d2a8d1d..1193a65 100644 --- a/RGB.NET.Core/Devices/IRGBDeviceProvider.cs +++ b/RGB.NET.Core/Devices/IRGBDeviceProvider.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; namespace RGB.NET.Core { @@ -31,7 +30,7 @@ namespace RGB.NET.Core /// /// Gets a collection registered to this device provider. /// - ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers { get; } + IReadOnlyList<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers { get; } #endregion diff --git a/RGB.NET.Core/RGBSurface.cs b/RGB.NET.Core/RGBSurface.cs index 6b9d726..3cebaa7 100644 --- a/RGB.NET.Core/RGBSurface.cs +++ b/RGB.NET.Core/RGBSurface.cs @@ -26,20 +26,15 @@ namespace RGB.NET.Core /// /// Gets a readonly list containing all loaded . + /// This collection should be locked when enumerated in a multi-threaded application. /// - public IEnumerable Devices - { - get - { - lock (_devices) - return new ReadOnlyCollection(_devices); - } - } + public IReadOnlyList Devices { get; } /// /// Gets a readonly list containing all registered . + /// This collection should be locked when enumerated in a multi-threaded application. /// - public IEnumerable UpdateTriggers => new ReadOnlyCollection(_updateTriggers); + public IReadOnlyList UpdateTriggers { get; } /// /// Gets a copy of the representing this . @@ -53,7 +48,7 @@ namespace RGB.NET.Core { get { - lock (_devices) + lock (Devices) return _devices.SelectMany(x => x); } } @@ -124,6 +119,9 @@ namespace RGB.NET.Core public RGBSurface() { _deltaTimeCounter = Stopwatch.StartNew(); + + Devices = new ReadOnlyCollection(_devices); + UpdateTriggers = new ReadOnlyCollection(_updateTriggers); } #endregion @@ -146,8 +144,8 @@ namespace RGB.NET.Core bool render = customData["render"] as bool? ?? true; bool updateDevices = customData["updateDevices"] as bool? ?? true; - lock (_updateTriggers) - lock (_devices) + lock (UpdateTriggers) + lock (Devices) { OnUpdating(updateTrigger, customData); @@ -178,7 +176,7 @@ namespace RGB.NET.Core public void Dispose() { List devices; - lock (_devices) + lock (Devices) devices = new List(_devices); foreach (IRGBDevice device in devices) @@ -267,7 +265,7 @@ namespace RGB.NET.Core /// The to attach. public void Attach(IRGBDevice device) { - lock (_devices) + lock (Devices) { if (string.IsNullOrWhiteSpace(device.DeviceInfo.DeviceName)) throw new RGBDeviceException($"The device '{device.DeviceInfo.Manufacturer} {device.DeviceInfo.Model}' has no valid name."); if (device.Surface != null) throw new RGBSurfaceException($"The device '{device.DeviceInfo.DeviceName}' is already attached to a surface."); @@ -287,7 +285,7 @@ namespace RGB.NET.Core /// true if the could be detached; false otherwise. public void Detach(IRGBDevice device) { - lock (_devices) + lock (Devices) { if (!_devices.Contains(device)) throw new RGBSurfaceException($"The device '{device.DeviceInfo.DeviceName}' is not attached to this surface."); @@ -314,7 +312,7 @@ namespace RGB.NET.Core private void UpdateSurfaceRectangle() { - lock (_devices) + lock (Devices) { Rectangle devicesRectangle = new(_devices.Select(d => d.Boundary)); Boundary = Boundary.SetSize(new Size(devicesRectangle.Location.X + devicesRectangle.Size.Width, devicesRectangle.Location.Y + devicesRectangle.Size.Height));