c# Collection was modified. enumeration operation might not execute.

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
Below is sample code which throwing error called Collection was modified. enumeration operation might not execute.

am i getting this error because i use AsParallel ?

.AsParallel().WithDegreeOfParallelism(5)

string StandardValue = ""

StandardValue = dtFilterDataFromAllData.AsEnumerable().AsParallel().WithDegreeOfParallelism(noofththreads)
.Where(w => w.Field<string>("BRTab") == BRTab
&& w.Field<string>("RowNumber") == RowNumber
&& w.Field<string>("StandardDate").Replace("A", "").Replace("E", "") == strPeriod.Replace("A", "").Replace("E", ""))
.Select(v => v.Field<string>("StandardValue"))
.FirstOrDefault();


if (StandardValue != null && StandardValue.ToString() != "")
{
//update Standard Value after processing
StandardValue = ProcessValue(StandardValue ?? "", strUnits, false, TabName, StandardLineItem, strPeriod.Replace("A", string.Empty).Replace("E", string.Empty));

dtFilterDataFromAllData.AsEnumerable().Where(w => w.Field<string>("BRTab") == BRTab
&& w.Field<string>("RowNumber") == RowNumber
&& w.Field<string>("StandardDate").Replace("A", "").Replace("E", "") == strPeriod.Replace("A", "").Replace("E", ""))
.ForEach(w =>
{
//update parent StandardValue
w["StandardValue"] = StandardValue;
});
dtFilterDataFromAllData.AcceptChanges();
}
can't i use .AsParallel in my above code ? thanks

Continue reading...
 
Back
Top