目标数组不够长?

编程入门 行业动态 更新时间:2024-10-06 16:16:52
本文介绍了目标数组不够长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

更多推荐

目标数组不够长?

本文发布于:2023-11-23 06:53:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620511.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   目标

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!