Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Collection was modified; Enumeration Operation may not execute

Collection was modified; Enumeration Operation may not execute

Scheduled Pinned Locked Moved C#
wpfwcftutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vijju2006
    wrote on last edited by
    #1

    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???

    C 1 Reply Last reply
    0
    • V Vijju2006

      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???

      C Offline
      C Offline
      carlop
      wrote on last edited by
      #2

      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

      V 1 Reply Last reply
      0
      • C carlop

        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

        V Offline
        V Offline
        Vijju2006
        wrote on last edited by
        #3

        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.

        C 1 Reply Last reply
        0
        • V Vijju2006

          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.

          C Offline
          C Offline
          carlop
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups