diff --git a/src/Avalonia.Base/Utilities/WeakEvent.cs b/src/Avalonia.Base/Utilities/WeakEvent.cs index c353e11263..0b32015a8a 100644 --- a/src/Avalonia.Base/Utilities/WeakEvent.cs +++ b/src/Avalonia.Base/Utilities/WeakEvent.cs @@ -49,6 +49,7 @@ public class WeakEvent : WeakEvent where TEventArgs : Event { private readonly WeakEvent _ev; private readonly TSender _target; + private readonly Action _compact; private WeakReference>?[] _data = new WeakReference>[16]; @@ -60,7 +61,7 @@ public class WeakEvent : WeakEvent where TEventArgs : Event { _ev = ev; _target = target; - + _compact = Compact; _unsubscribe = ev._subscribe(target, OnEvent); } @@ -110,7 +111,7 @@ public class WeakEvent : WeakEvent where TEventArgs : Event if(_compactScheduled) return; _compactScheduled = true; - Dispatcher.UIThread.Post(Compact, DispatcherPriority.Background); + Dispatcher.UIThread.Post(_compact, DispatcherPriority.Background); } void Compact()