0
병렬 foreach가 실행을 완료하기 전에 연결을 닫는 데 문제가 있습니다. 정기적 인 foreach 루프를 실행했을 때 속도가 느려졌지만 모든 것을 반환합니다. 일단 병렬 foreach로 변경하면 이제 데이터의 약 95 %가 반환되고 종료됩니다. 아마병렬 Foreach 경쟁 조건
var USPostalCodes = repository.GetUSPostalCodes();
var CAPostalCodes = repository.GetCAPostalCodes();
Parallel.ForEach(spreadsheetinfo, location =>
{
LocationData Locationdata = new LocationData()
{
id = location.Id,
Market = repository.GetMarketsForPostalCode(location.PostalCode, uploadedFile, USPostalCodes, CAPostalCodes),
};
locationlist.Add(Locationdata);
});
I added the following code to check and see what was going on, and that fixed it so that it is returning all rows so i know that a race condition exists but what i can't figure out is why and how ot fix it. any suggestions would be greatly appreciated
Console.WriteLine("Processing {0} on thread {1}", Locationdata,
Thread.CurrentThread.ManagedThreadId);