작업 병렬 라이브러리를 사용하여 아래에 표시된대로 작업 체인을 설정하고 있지만 이해할 수없는 예외 처리 경험이 있습니다.잡힌 AggregateException에 예외가 없습니다.
나는 Parallel.ForEach를 사용하고 다음 메소드를 호출하는 Action을 호출한다. 이 Parallel.ForEach는 try ... catch (AggregateException)로 래핑되고 예외가 발생하면 Parallel 브랜치 중 하나에서와 마찬가지로 SchemaValidation 예외가 발생하면 AggregateException에서 예외가 발생합니다.
그러나 내가 얻은 것은 '작업이 취소되었습니다.'- TaskCanceledException입니다. 내 SchemaValidationException은 어디에 있습니까?
private static void ProcessChunk(Task<ISelectedChunk> selectionTask,
IRepository repository,
IIdentifiedExtractChunk identifiedExtractChunk,
IBatchRunConfiguration batchRunConfiguration,
IBatchRun batchRun,
ILog log,
IAuthenticationCertificate authenticationCertificate,
IFileSystem fileSystem,
long batchRunRid)
{
var transformationTask = selectionTask.ContinueWith(TransformationFunction.Transformation(identifiedExtractChunk, batchRunConfiguration, batchRun),
TaskContinuationOptions.NotOnFaulted);
var schemaValidationTask = transformationTask.ContinueWith(SchemaValidationFunction.SchemaValidationTask(batchRunConfiguration),
TaskContinuationOptions.NotOnFaulted);
var compressTask = schemaValidationTask.ContinueWith(CompressFunction.CompressTask(identifiedExtractChunk),
TaskContinuationOptions.NotOnFaulted);
var encryptTask = compressTask.ContinueWith(EncryptionFunction.EncryptTask(authenticationCertificate),
TaskContinuationOptions.NotOnFaulted);
var fileGenerationTask = encryptTask.ContinueWith(FileGenerationFunction.FileGenerationTask(identifiedExtractChunk, batchRunConfiguration, fileSystem),
TaskContinuationOptions.NotOnFaulted);
// Take the time before we start the processing
DateTime startBatchItemProcessing = DateTime.Now;
// Start with the Selection Task
selectionTask.Start();
// And wait on the last task in the chain
fileGenerationTask.Wait();
// Take the time at the end of the processing
DateTime endBatchItemProcessing = DateTime.Now;
// Record all the relevant information and add it to the collection
IBatchChunkProcessed batchChunkProcessed = GetBatchItemProcessed(identifiedExtractChunk, batchRunRid, fileGenerationTask.Result, transformationTask.Result.Item2, startBatchItemProcessing, endBatchItemProcessing);
BatchItemsProcessed.Add(batchChunkProcessed);
여기서 '작업'을 사용하는 이유는 무엇입니까? 모든 메소드를 순차적으로 실행하지 않는 이유는 무엇입니까? – svick
코드는 질문과 관련이없는 것 같습니다. 예외를 포착하고 처리하는 코드를 게시하십시오. –
@svick - 전달 된 선택 작업이 병렬 처리됩니다. 또한 이들은 다른 상황에서 쉽게 재사용 될 수 있고 가능하다면 루트 작업으로 만들어 질 수있는 개별 빌딩 블록 작업입니다. – Ciaran