开发者

Obscure IndexOutOfRangeException in .NET 4

开发者 https://www.devze.com 2023-02-20 21:07 出处:网络
I have an IndexOutOfRangeException that I can not reproduce in debug mode, according to the stack trace from where the exception is thrown it\'s occurring on the line \"return true;\" No array indexin

I have an IndexOutOfRangeException that I can not reproduce in debug mode, according to the stack trace from where the exception is thrown it's occurring on the line "return true;" No array indexing on that line, and not even any array indexing in the procedure the exception is apparently being throw in. So I'm guessing the stack trace might be a bit of a red herring.

Does anyone know what might cause this behaviour? I do have multiple threads accessing开发者_开发知识库 the object in which the exception is being thrown, but they are only reading from the object, there are no modifications being made. Might this still be a problem?

Any pointers as to where I should start looking to fix this would be much appreciated.


You might want to make a local copy before iterating, or find a way to lock collection before iterating.

A fairly easy read on threading usage in C#

(Oftentimes, it's the next line after the actual line that throws exception is shown in debugger.)

0

精彩评论

暂无评论...
验证码 换一张
取 消