我一直在多线程 .net 3.5 应用程序上遇到此错误
ERROR 26 Exception thrown. Details: 'System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
我想我知道如何修复它(在适当的地方添加锁),但我希望能够在我的本地环境中重现这个问题,所以我将确保我修复了它并且我能够添加对其进行单元测试。
你知道任何一致的方法来重新创建它吗?
最佳答案
Dictionary<string, string> dict = new Dictionary<string, string>();
Task.Factory.StartNew(() => { while (true) dict["a"] = "a"; });
Task.Factory.StartNew(() => { while (true) dict.Remove("a"); });
关于c# - 如何重新创建 "Index was outside the bounds of the array"添加项目到字典?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12748275/