Under what circumstance System.Collections.ArrayList.Add throws IndexOutOfRangeException?

后端 未结 3 1754
梦谈多话
梦谈多话 2020-12-06 00:50

We are experiencing weird bug at production environment we cannot debug nor inject logging code. I am trying to figure this up but following stack trace confuse me.

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-06 00:59

    That's almost certainly a concurrency issue... You probably have two threads that modify the collection at the same time, and the ArrayList class is not designed to support concurrent access. A race condition occurs, which sometimes leads one of the threads to attempt to write at a position outside the bounds of the array.

    Try to protect all accesses to the collection using lock statements, or use a synchronized wrapper of the collection (using the ArrayList.Synchronized method)

提交回复
热议问题