Below is code which I am using in Parrllel.Foreach. But it is taking same time as normal foreach. Here filingDataItems, nonPeriodic, periodiccells are data tables. Does this happening due to data tables?
System.Threading.Tasks.Parallel.ForEach(tempfilingReferences, T2 => { Filing f = new Filing( T2.Id, T2.DocumentPeriod, T2.FilingDate, T2.VersionId, T2.DocumentId, T2.PrimaryPeriodTypeId, T2.IssuedAsPreliminaryFlag, T2.IssuedAsAmendmentFlag, T2.FilingDetails, T2.CompanyId, GetFilingDataItems(filingDataItems, T2.Id, nonPeriodic, periodiccells, filingToPeriodList, DPTPList, posList), GetPeriods(filingToPeriodList, periodInfoList, T2.Id), GetFilingToPeriods(filingToPeriodList, T2.Id), true, false, AuditedDataType.Financials, T2.FilingTypeList ); lock (filingListnew) { filingListnew.Add(f); } });
Parallel.ForEachlock(), the methodsGetFilingDataItems(),GetPeriods()andGetFilingToPeriods()may very well be slower when called in parallel.