報的是如下的錯誤
【OnH1Work error:索引等于或大于陣列的長度,或者字典中的元素數量大于從索引到目標陣列末尾的可用空間。 在 System.Collections.Concurrent.ConcurrentDictionary`2.System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.CopyTo(KeyValuePair`2[] array, Int32 index)
在 System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
在 System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
在 Device.MainControl.GetTestItem()
在 Device.MainControl.OnH1Work()】
原始碼:
定義ConcurrentDictionary<string, SendItemModel> scanBarAfterItemList = new ConcurrentDictionary<string, SendItemModel>();
private SendItemModel GetTestItem()
{
SendItemModel itemModel = null;
List<KeyValuePair<string, SendItemModel>> tempSortList = this.scanBarAfterItemList.ToList();
string curKey = string.Empty;
tempSortList.Sort(this.sortList);
foreach (KeyValuePair<string, SendItemModel> item in tempSortList)
{
curKey = item.Key;
this.scanBarAfterItemList.TryGetValue(curKey, out itemModel);
if (itemModel != null && itemModel.ItemStatus == EnumItemTestStatus.ITSSendToThread)
{
return itemModel;
}
}
return null;
}
這是哪里報了這個錯,看不出來,請大家幫忙
uj5u.com熱心網友回復:
感覺是這句 this.scanBarAfterItemList.TryGetValue(curKey, out itemModel);你把SendItemModel itemModel = null;改成 SendItemModel itemModel = new SendItemModel();試試看
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/53969.html
標籤:ASP.NET
