作业被不同的线程添加到HashSet
中,并引发此错误。有什么解决办法吗?
ConcurrentDictionary<myKey,HashSet<Job>> _dictKeyJob;
_dictKeyJob.AddOrupdate(myKey,key =>
{
return new HashSet<Job>({ Job };
},(key,hashJobs) =>
{
if (Job.Status == eStatus.Cancelled)
{
hashJobs.Remove(Job);
}
else
{
hashJobs.Add(Job);
}
return hashJobs;
});
例外:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Collections.Generic.HashSet`1.SetCapacity(Int32 newSize,Boolean forceNewHashCodes)
at System.Collections.Generic.HashSet`1.AddIfNotPresent(T value)
at Raj.OPS.Common.Test.<>c__DisplayClass38_0.<SetOrAddKey>b__1(mKey key,HashSet`1 hashJobs) in
at System.Collections.Concurrent.ConcurrentDictionary`2.**AddOrupdate**(TKey key,Func`2 addValueFactory,Func`3 updateValueFactory)