fix: invocation loop inversed

This commit is contained in:
Syntriax 2025-07-06 22:21:20 +03:00
parent a1feb0bad3
commit 8f03628bd6

View File

@ -80,7 +80,7 @@ public class Event
/// </summary> /// </summary>
public void Invoke() public void Invoke()
{ {
for (int i = 0; i < listeners.Count; i++) for (int i = listeners.Count - 1; i >= 0; i--)
try { listeners[i].Invoke(); } try { listeners[i].Invoke(); }
catch (Exception exception) catch (Exception exception)
{ {
@ -195,7 +195,7 @@ public class Event<TSender>
/// <param name="sender">The caller that's triggering this event.</param> /// <param name="sender">The caller that's triggering this event.</param>
public void Invoke(TSender sender) public void Invoke(TSender sender)
{ {
for (int i = 0; i < listeners.Count; i++) for (int i = listeners.Count - 1; i >= 0; i--)
try { listeners[i].Invoke(sender); } try { listeners[i].Invoke(sender); }
catch (Exception exception) catch (Exception exception)
{ {
@ -318,7 +318,7 @@ public class Event<TSender, TArguments>
/// <param name="args">The arguments provided for this event.</param> /// <param name="args">The arguments provided for this event.</param>
public void Invoke(TSender sender, TArguments args) public void Invoke(TSender sender, TArguments args)
{ {
for (int i = 0; i < listeners.Count; i++) for (int i = listeners.Count - 1; i >= 0; i--)
try { listeners[i].Invoke(sender, args); } try { listeners[i].Invoke(sender, args); }
catch (Exception exception) catch (Exception exception)
{ {