我定义了一个 SortedDictionary:
private SortedDictionary<int, SingleQcCalculation> m_dicTagsToCalc;
我正在迭代它并在值内设置一个属性:
foreach (KeyValuePair<int, SingleQcCalculation> pairSingleCalc in m_dicTagsToCalc)
{
try
{
pairSingleCalc.Value.m_QCtoCalc.m_CurGroupID = pairSingleCalc.Value.m_ChangedQcGroupId;
pairSingleCalc.Value.m_QCtoCalc.CalculateQCExpression(pairSingleCalc.Value.m_OPCChangeTime, pairSingleCalc.Value.m_calcTime);
}
catch (Exception ex)
{
logger.Error(LogTopicEnum.DA,"Error calculating calced QC (id=" + pairSingleCalc.Value.m_QCtoCalc.ID.ToString() + ")" , ex);
}
}
出于某种原因,我得到了这个例外:
DoQCsCalculations: error while calculating calced tags
System.InvalidOperationException: Collection was modified after the enumerator was instantiated.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.SortedSet`1.Enumerator.MoveNext()
现在,我没有更改字典中的值或键,没有其他线程使用字典。
为什么我会收到此错误?
谢谢, 奥马尔