Browse Source

Copy listeners before notifying.

As raising the event can cause the listeners to change.
pull/4533/head
Steven Kirk 6 years ago
parent
commit
562e6bb3ef
  1. 8
      src/Avalonia.Controls/Utils/CollectionChangedEventManager.cs

8
src/Avalonia.Controls/Utils/CollectionChangedEventManager.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Avalonia.Threading; using Avalonia.Threading;
using Avalonia.Utilities; using Avalonia.Utilities;
@ -118,16 +119,17 @@ namespace Avalonia.Controls.Utils
if (sender is INotifyCollectionChanged incc && _entries.TryGetValue(incc, out var listeners)) if (sender is INotifyCollectionChanged incc && _entries.TryGetValue(incc, out var listeners))
{ {
var l = listeners.ToList();
if (Dispatcher.UIThread.CheckAccess()) if (Dispatcher.UIThread.CheckAccess())
{ {
Notify(incc, e, listeners); Notify(incc, e, l);
} }
else else
{ {
var inccCapture = incc; var inccCapture = incc;
var eCapture = e; var eCapture = e;
var listenersCapture = listeners; Dispatcher.UIThread.Post(() => Notify(inccCapture, eCapture, l));
Dispatcher.UIThread.Post(() => Notify(inccCapture, eCapture, listenersCapture));
} }
} }
} }

Loading…
Cancel
Save