# HG changeset patch # User IBBoard # Date 1252525034 0 # Node ID 1486ccd744dc1cc714eab7e4e3649f611e60f397 # Parent 7ace7d2249acdc532f6848d04c4c8ab35912b546 Fixes #135: Closing army crashes WinForms * Simple solution: Cache the open windows as an array then close them from the array to avoid iterating over an collection that gets modified! diff -r 7ace7d2249ac -r 1486ccd744dc FrmArmyTree.cs --- a/FrmArmyTree.cs Mon Sep 07 20:10:40 2009 +0000 +++ b/FrmArmyTree.cs Wed Sep 09 19:37:14 2009 +0000 @@ -139,8 +139,11 @@ { htNodes.Clear(); treeView.Nodes.Clear(); + ICollection unitFormsCollection = htUnitWindows.Values; + FrmUnit[] unitForms = new FrmUnit[unitFormsCollection.Count]; + unitFormsCollection.CopyTo(unitForms, 0); - foreach (FrmUnit window in htUnitWindows.Values) + foreach (FrmUnit window in unitForms) { window.Close(); }