mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
Prevented concurrent list operations when modifying decorators
This commit is contained in:
parent
86e9bb293b
commit
09e514c813
@ -78,6 +78,7 @@ namespace RGB.NET.Core
|
|||||||
/// <param name="color">The <see cref="Color"/> to be modified.</param>
|
/// <param name="color">The <see cref="Color"/> to be modified.</param>
|
||||||
protected virtual Color ApplyDecorators(Rectangle rectangle, BrushRenderTarget renderTarget, Color color)
|
protected virtual Color ApplyDecorators(Rectangle rectangle, BrushRenderTarget renderTarget, Color color)
|
||||||
{
|
{
|
||||||
|
lock (Decorators)
|
||||||
foreach (IBrushDecorator decorator in Decorators)
|
foreach (IBrushDecorator decorator in Decorators)
|
||||||
if (decorator.IsEnabled)
|
if (decorator.IsEnabled)
|
||||||
color = decorator.ManipulateColor(rectangle, renderTarget, color);
|
color = decorator.ManipulateColor(rectangle, renderTarget, color);
|
||||||
|
|||||||
@ -11,11 +11,20 @@ namespace RGB.NET.Core
|
|||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
private List<T> _decorators = new List<T>();
|
private readonly List<T> _decorators = new List<T>();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a readonly-list of all <see cref="IDecorator"/> attached to this <see cref="IDecoratable{T}"/>.
|
/// Gets a readonly-list of all <see cref="IDecorator"/> attached to this <see cref="IDecoratable{T}"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected IReadOnlyCollection<T> Decorators => new ReadOnlyCollection<T>(_decorators);
|
protected IReadOnlyCollection<T> Decorators { get; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
protected AbstractDecoratable()
|
||||||
|
{
|
||||||
|
Decorators = new ReadOnlyCollection<T>(_decorators);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -23,9 +32,12 @@ namespace RGB.NET.Core
|
|||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void AddDecorator(T decorator)
|
public void AddDecorator(T decorator)
|
||||||
|
{
|
||||||
|
lock (Decorators)
|
||||||
{
|
{
|
||||||
_decorators.Add(decorator);
|
_decorators.Add(decorator);
|
||||||
_decorators = _decorators.OrderByDescending(x => x.Order).ToList();
|
_decorators.Sort((d1, d2) => d1.Order.CompareTo(d2.Order));
|
||||||
|
}
|
||||||
|
|
||||||
decorator.OnAttached(this);
|
decorator.OnAttached(this);
|
||||||
}
|
}
|
||||||
@ -33,6 +45,7 @@ namespace RGB.NET.Core
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void RemoveDecorator(T decorator)
|
public void RemoveDecorator(T decorator)
|
||||||
{
|
{
|
||||||
|
lock (Decorators)
|
||||||
_decorators.Remove(decorator);
|
_decorators.Remove(decorator);
|
||||||
|
|
||||||
decorator.OnDetached(this);
|
decorator.OnDetached(this);
|
||||||
@ -41,7 +54,12 @@ namespace RGB.NET.Core
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void RemoveAllDecorators()
|
public void RemoveAllDecorators()
|
||||||
{
|
{
|
||||||
foreach (T decorator in Decorators.ToList())
|
IEnumerable<T> decorators;
|
||||||
|
|
||||||
|
lock (Decorators)
|
||||||
|
decorators = Decorators.ToList();
|
||||||
|
|
||||||
|
foreach (T decorator in decorators)
|
||||||
RemoveDecorator(decorator);
|
RemoveDecorator(decorator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user