Collection was modified , enumeration operation may not execute.

  • Thread starter Thread starter Priya0867
  • Start date Start date
P

Priya0867

Guest
I am getting this error , not sure why this error is occurring . Could you please help.


var carrierList = GetAllCarriersForInputRecords(orgService, importedEnrollments);

var options = new ParallelOptions() { MaxDegreeOfParallelism = maxThreads };
//Loop Through Record Keeper Records
ConcurrentBag<ImportedEnrollmentStatus> enrollmentList = new ConcurrentBag<ImportedEnrollmentStatus>(importedEnrollments);
Parallel.ForEach(enrollmentList, options, () => { return GetOrgServiceProxy(_orgServiceManagement, _authCredentials); },
(enrollmentStatus, loopState, index, threadProxy) =>
{
threadProxy.EnableProxyTypes();
var orgThreadProxy = GetOrgServiceProxy(_orgServiceManagement, _authCredentials);
orgThreadProxy.EnableProxyTypes();

var currentOutput = new JobProcessOutputStatus(true);
var logic = new ValidationLogic(orgThreadProxy);


try
{
//if we get an actual error, we don't want the entire process to quit
currentOutput = logic.ValidateImportedEnrollmentStatus(enrollmentStatus, carrierList, jobTracking, currentOutput.RowCount, currentOutput.TotalSuccess);

Interlocked.Add(ref totalProcessed, 1);
Interlocked.Add(ref totalSuccess, currentOutput.Success ? 1 : 0);
Log.InfoFormat("{0}. Processed {1} {2}\n", totalProcessed, enrollmentStatus.exch_FirstName, enrollmentStatus.exch_LastName);
}
catch (Exception e)
{
exceptions.Enqueue(e);

logic.UpdateLogic.AddProcessingNote("9000", string.Format("Processing Ended With an Error: {0}", e.Message), (int)exch_processingnoteseverity._300ErrorOverridable, enrollmentStatus);

currentOutput.Success = false;
}

if (totalProcessed % jobUpdateIncrement == 0)
{
jobFileTracking.UpdateJobFileTracking(orgService, false, totalProcessed, totalSuccess, totalProcessed - totalSuccess);
jobTracking.UpdateJobTrackingErrorCounts(orgService, totalProcessed - totalSuccess);
}

//return proxy to the next iteration in the current thread's loop
return orgThreadProxy;
},
threadProxy => threadProxy.Dispose());

jobFileTracking.UpdateJobFileTracking(orgService, true, totalProcessed, totalSuccess, totalProcessed - totalSuccess);
jobTracking.UpdateJobTrackingErrorCounts(orgService, totalProcessed - totalSuccess);

if (exceptions.Count > 0)
throw new AggregateException(exceptions);

}

Continue reading...
 
Back
Top