public void reset() { try//exception will be thrown when cell is removed while iterating, but just keep doing it until you do it for all cells { foreach (Cell cell in (this.CellsToSave)) { cell.Text = "";//this will trigger cell to be removed from the CellsToSave HashSet cell.BGColor = -1; } } catch { this.reset(); } this.m_UnRedoSystem = new UndoSystem(); }