Collection was modified; enumeration operation may not execute

后端 未结 16 2548
南旧
南旧 2020-11-21 06:05

I can\'t get to the bottom of this error, because when the debugger is attached, it does not seem to occur.

Collection was modified; enumeration operatio

16条回答
  •  死守一世寂寞
    2020-11-21 07:04

    You can also lock your subscribers dictionary to prevent it from being modified whenever its being looped:

     lock (subscribers)
     {
             foreach (var subscriber in subscribers)
             {
                   //do something
             }
     }
    

提交回复
热议问题