diff --git a/GFramework.Core/events/PriorityEvent.cs b/GFramework.Core/events/PriorityEvent.cs index e3dc4c6..5be3376 100644 --- a/GFramework.Core/events/PriorityEvent.cs +++ b/GFramework.Core/events/PriorityEvent.cs @@ -191,11 +191,13 @@ public class PriorityEvent : IEvent private List<(int Priority, Action? Handler, Action>? ContextHandler, bool IsContext)> MergeAndSortHandlers(T t) { + var normalSnapshot = _handlers.ToArray(); + var contextSnapshot = _contextHandlers.ToArray(); // 使用快照避免迭代期间修改 - return _handlers + return normalSnapshot .Select(h => (h.Priority, Handler: (Action?)(() => h.Handler.Invoke(t)), ContextHandler: (Action>?)null, IsContext: false)) - .Concat(_contextHandlers + .Concat(contextSnapshot .Select(h => (h.Priority, Handler: (Action?)null, ContextHandler: (Action>?)h.Handler, IsContext: true))) .OrderByDescending(h => h.Priority)