Collection was modified; Enumeration Operation may not execute
-
I have a piece of code in which collection is assigned to dropdown list's data source property for binding data. When multiple clients access the site simultaniously the following exception was being thrown:"Collection was modified; Enumeration Operation may not execute". Any idea about y this is happening and how to get this code work???
-
I have a piece of code in which collection is assigned to dropdown list's data source property for binding data. When multiple clients access the site simultaniously the following exception was being thrown:"Collection was modified; Enumeration Operation may not execute". Any idea about y this is happening and how to get this code work???
-
Is not allowed to modify any item of a collection in any way while you're inside the foreach loop on that collection. You may try to lock the piece of code, something like the following lock(this) { ... } paco
-
Thank you carlopagliei for the reply; but i am not using the foreach statement. I have a code like ddlTest.DataSource= TestCollection; ddlTest.DataBind(); Otherthan populating the collection from database, i am not manipulating the collection.
It was only an example. You don't use foreach but probably the problem is that while DataBind() method enumerates over the TestCollection another piece of code (maybe the same but from another thread) is doing the same. So try to lock the code that acess TestCollection before use it: lock (TestCollection) { ddlTest.DataSource= TestCollection; ddlTest.DataBind(); } paco