에서 읽을 수 없습니다. 내가 총 수를 인쇄하고, 다음 행에서Parallel.ForEach와는 내가 여러 가지가 URL의 피드를 포함하는 텍스트 파일을 폐쇄 TextReader를 예외
var URLs = File.ReadLines(Path.GetFullPath(@"Resources\FeedList.txt"));
:
Console.WriteLine("Total Number of feeds : {0}",URLs.Count());
을 그리고 그 후 나는 Parellel를 사용하고 난 다음 코드를 사용하여 콜렉션 (는 IEnumerable)에서 모든 URL의를 읽고있다. 각각의 URL에 해당하는 로직을 수행하기 위해 각각의 구문. 다음, 나는 코드를 사용하고 있습니다 :
Parallel.ForEach(URLs, (url) =>
{
// Some business logic
});
문제는, 내가 URL의 예를 호출하는 코드, 백작의 수를 인쇄 최대한 빨리 코드를 추가로 예외를 다음 얻고있다() 메소드 URL 개체. 예외 :
Total Number of feeds : 78
Unhandled Exception: System.AggregateException: One or more errors occurred. ---> System.ObjectDisposedException: Cannot read from a closed TextReader.
at System.IO.__Error.ReaderClosed()
at System.IO.StreamReader.ReadLine()
at System.IO.File.<InternalReadLines>d__0.MoveNext()
at System.Collections.Concurrent.Partitioner.DynamicPartitionerForIEnumerable`1.InternalPartitionEnumerator.GrabNextChunk(Int32 requestedChunkSize)
at System.Collections.Concurrent.Partitioner.DynamicPartitionEnumerator_Abstract`2.MoveNext()
at System.Threading.Tasks.Parallel.<>c__DisplayClass32`2.<PartitionerForEachWorker>b__30()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
at System.Threading.Tasks.Task.<>c__DisplayClass7.<ExecuteSelfReplicating>b__6(Object)
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWi
at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3
at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, Action`1 body)
at DiscoveringGroups.Program.Main(String[] args) in C:\Users\Pawan Mishra\Documents\Visual Studio 2010\Projects\ProgrammingCollectiveIntelligence\DiscoveringGroups\Pro
Press any key to continue . . .
그리고 카운트 값을 인쇄하는 줄을 제거/주석 처리하면 Parallel.ForEach 루프가 정상적으로 실행됩니다.
사람은 여기에 잘못가는 뭐죠로 어떤 생각을 가지고 있습니까? 당신이 필요하지 않은 경우
'비즈니스 논리'에서 어떤 일이 벌어지고 있습니까? –