Announcement

Collapse
No announcement yet.

IC:Collection was modified; enumeration operation may not execute

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    IC:Collection was modified; enumeration operation may not execute

    Hi all,

    Has anybody seen a message like this from one of their plugins before:
    Error displaying device (1) <<device name>> - IC:Collection was modified; enumeration operation may not execute. Check with the owner of the plugin that created this device.
    A user of one of my plugins see's this but I can't replicate

    #2
    Usually this happens inside 'foreach' loop when collection changes, i.e. you delete or add items inside the loop.

    To be safe I create a copy of the collection, i.e.
    Code:
    foreach(var v in vars.[B]ToArray()[/B])
    {
    }

    Comment


      #3
      I agree with what Alexbk66 says, but I also wonder if this could be caused by activity on another thread that is affecting the collection in the problematic thread. Timing issues in multi threaded applications can be tough to duplicate.

      I’m a long time .Net developer, but fairly new to plug-in development so I do not actually know of the correction between the HomeSeer process and a plug-in console process is done in a multi-threaded fashion. But I’m assuming it probably is.

      Comment


        #4
        Originally posted by bradleyward View Post
        I agree with what Alexbk66 says, but I also wonder if this could be caused by activity on another thread that is affecting the collection in the problematic thread. Timing issues in multi threaded applications can be tough to duplicate.

        I’m a long time .Net developer, but fairly new to plug-in development so I do not actually know of the correction between the HomeSeer process and a plug-in console process is done in a multi-threaded fashion. But I’m assuming it probably is.
        Yeah, it's a possibility. That's actually the reason I create a local copy of the array.

        Modifying the collection explicitly inside foreach loop doesn't work anyways.

        Comment


          #5
          Originally posted by alexbk66 View Post

          Yeah, it's a possibility. That's actually the reason I create a local copy of the array.

          Modifying the collection explicitly inside foreach loop doesn't work anyways.
          I like it! I had never thought about the fact that the ToArray method does make a copy. So although I do consider that to be a quick “hack” instead of the much more time consuming effort of proper multi thread coordination (using locks, etc), if not abused it sure would do the trick! Thanks for sharing.

          Comment


            #6
            Yeah, it is a quick hack, only in rare cases where it's not breaking anything.

            Comment

            Working...
            X