Queue Collection changed

  • Thread starter Thread starter Tamir Khason
  • Start date Start date
T

Tamir Khason

I have a queue, wich recieves a lot of messages (between 10 and 100 a
second)
There is thread that takes care on this queue, but as far as I see it can
not follow the messages so "Collection was modified; enumeration operation
may not execute." exception thows. How to take care on it

txn

BTW. this not any other problem then reading from queue. I double checked
it.
 
Tamir.

Not sure what type of queue you're using or how you're handling it.

However, the error you're getting is from using an enumerator and modifying
the
underlying collection. If you must modify it (or it is being modified for
you), switch
from a "foreach" loop to a "for" or "while" loop.
 
It's possible one thread could be in the middle of a foreach block
when another thread does an Insert or Delete. Are you using lock or
another form of thread synchronization?
 
Back
Top