Obscure IndexOutOfRangeException in .NET 4
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.)
精彩评论