我有一个使用以下方法的课程:
I have a class with the following method:
public List<Bike> bikesCopy { get { List<Bike> bs; lock (_bikes) bs = new List<Bike>(_bikes); return bs; } }复制另一个列表private List<Bike> _bikes;
现在奇怪的是,我收到以下错误:
The strange thing now is, that I get the following error:
目标数组不够长.检查destIndex和length,以及数组的下界.
Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
这是什么问题?
推荐答案我会说错误在于对象 _bikes 不是线程安全的.如前所述,某处对 _bikes 对象进行了修改,但未对其进行锁定.
I would say the error lies in the object _bikes not being thread safe. As commented, somewhere there is a modify of the _bikes object that is not being lock'ed.
这是一秒钟的错误,当测量 _bikes 的大小时,变量 bs 设置为大小X.在即将填充列表的下一瞬间, _bikes 对象的大小增加了,从而出现了错误.
It is a split second error where the variable bs is set up to a size X when the size of _bikes is measured. In the next split second as it is about to fill the list, the _bikes object has increased in size giving the error.
因此仔细检查您的代码.找到您的 _bikes 对象的所有引用,并确保它们是线程安全处理的(带锁).
So go over your code. Find all references of your _bikes object and make sure they are thread safe handled (with lock).
更多推荐
目标数组不够长?
发布评论