错误信息:
InvalidOperationException: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.
dictionary数据类型是非线程安全的,并发访问同一个内容字典会抛并发冲突
解决:
Dictionary换成ConCurrentDictionary,线程安全
本文探讨了在多线程环境下使用dictionary数据类型时遇到的InvalidOperationException错误,详细解释了错误产生的原因,即并发访问导致的非线程安全问题,并提供了解决方案,建议将Dictionary替换为ConCurrentDictionary以确保线程安全。
1658

被折叠的 条评论
为什么被折叠?



