Mat*_*vic 2 c# multithreading exception list
尝试清除列表时,我收到以下异常.
System.IndexOutOfRangeException occurred
HResult=-2146233080
Message=Index was outside the bounds of the array.
Source=mscorlib
StackTrace:
at System.Array.Clear(Array array, Int32 index, Int32 length)
at System.Collections.Generic.List`1.Clear()
at SystemFilterFactory.ResetSystemFilters() in d:\Source\SystemFilterFactory.cs:line 57
InnerException:
Run Code Online (Sandbox Code Playgroud)
没有显示真正的异常,该列表的基础是给出以下异常
目标数组不够长.检查destIndex和length,以及数组的下限.
我实际上是在发布我的问题LIST <> AddRange抛出ArgumentException之前找到了这个帖子的原因
然而,这需要更多的搜索,因为我没想到列表中存在真正的问题.
事实证明,由于List不是线程安全的,因此在列表上对多个线程同时更改大小的操作可以使得该列表上的任何内容都无法正常工作.
因此,对于在列表上执行操作,请确保以线程安全的方式执行此操作.
归档时间: |
|
查看次数: |
2275 次 |
最近记录: |