From a2ff94137741bb87578138d46ed2f530c277165c Mon Sep 17 00:00:00 2001 From: Isaac Daly Date: Sat, 18 May 2024 22:14:28 +1000 Subject: [PATCH] Avoid collection modification --- src/Whim/Store/MonitorSector/MonitorSector.cs | 4 +++- src/Whim/Store/WindowSector/WindowSector.cs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Whim/Store/MonitorSector/MonitorSector.cs b/src/Whim/Store/MonitorSector/MonitorSector.cs index f49d7284e..c290ac710 100644 --- a/src/Whim/Store/MonitorSector/MonitorSector.cs +++ b/src/Whim/Store/MonitorSector/MonitorSector.cs @@ -31,8 +31,10 @@ public override void Initialize() public override void DispatchEvents() { - foreach (EventArgs eventArgs in _events) + // Use index access to prevent the list from being modified during enumeration. + for (int idx = 0; idx < _events.Count; idx++) { + EventArgs eventArgs = _events[idx]; switch (eventArgs) { case MonitorsChangedEventArgs args: diff --git a/src/Whim/Store/WindowSector/WindowSector.cs b/src/Whim/Store/WindowSector/WindowSector.cs index a0d0b2f58..3ddba32ad 100644 --- a/src/Whim/Store/WindowSector/WindowSector.cs +++ b/src/Whim/Store/WindowSector/WindowSector.cs @@ -43,8 +43,10 @@ public override void Initialize() public override void DispatchEvents() { - foreach (EventArgs eventArgs in _events) + // Use index access to prevent the list from being modified during enumeration. + for (int idx = 0; idx < _events.Count; idx++) { + EventArgs eventArgs = _events[idx]; switch (eventArgs) { case WindowAddedEventArgs args: