目标数组不够长? [英] Destination Array not long enough?

查看:476
本文介绍了目标数组不够长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用以下方法的课程:

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).

这篇关于目标数组不够长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆