rifter1818 Posted September 30, 2004 Posted September 30, 2004 I wrote up a very simple bitmap manager using a hashtable, but when i use the remove function it eventually throws the error (at a seemingly random point) "An unhandled exception of type 'System.InvalidOperationException' occurred in system.windows.forms.dll Aditional information: Collection was modified; enumeration operation may not execute." Well lets see here keywords MODIFIED, MAY. MODIFIED of course it was modified, i just removed almost all of its members your dang right modified. MAY i dont care if it may not continue it dang well should and will continue however. If anyone can give me a hand that would be great public void Flush(string KeyContains) { //hbitmaps is the hashtable in question, all keys are strings all values bitmaps. foreach(object t in hbitmaps.Keys) if(((string)t).IndexOf(KeyContains) != -1) hbitmaps.Remove(t); } Quote
*Experts* mutant Posted October 1, 2004 *Experts* Posted October 1, 2004 You are trying to modify (delete in this case) the collection while it is being enumerated, which is not possible because it will mess up the enumeration process. Those keywords you just mentioned explain very well why there was an exception thrown :). Quote
rifter1818 Posted October 5, 2004 Author Posted October 5, 2004 You are trying to modify (delete in this case) the collection while it is being enumerated' date=' which is not possible because it will mess up the enumeration process. Those keywords you just mentioned explain very well why there was an exception thrown :).[/quote'] Fair enough, i was just getting frustrated (and didnt understand what it ment be enumerated) Correct me if im wrong (and it will when i try it) but the problem is that its changing the hashtable in a foreach loop, so if i allready cache all of the keys that i need (dont use a foreach loop) it will work? (and thanks for your help.) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.