comparison FrmArmyTree.cs @ 44:1486ccd744dc

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!
author IBBoard <dev@ibboard.co.uk>
date Wed, 09 Sep 2009 19:37:14 +0000
parents 740350673006
children 1c74b51abac1
comparison
equal deleted inserted replaced
43:7ace7d2249ac 44:1486ccd744dc
137 137
138 private void ClearArmy() 138 private void ClearArmy()
139 { 139 {
140 htNodes.Clear(); 140 htNodes.Clear();
141 treeView.Nodes.Clear(); 141 treeView.Nodes.Clear();
142 142 ICollection unitFormsCollection = htUnitWindows.Values;
143 foreach (FrmUnit window in htUnitWindows.Values) 143 FrmUnit[] unitForms = new FrmUnit[unitFormsCollection.Count];
144 unitFormsCollection.CopyTo(unitForms, 0);
145
146 foreach (FrmUnit window in unitForms)
144 { 147 {
145 window.Close(); 148 window.Close();
146 } 149 }
147 150
148 htUnitWindows.Clear(); 151 htUnitWindows.Clear();