小编Cia*_*ran的帖子

我捕获的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 …
Run Code Online (Sandbox Code Playgroud)

.net c# exception task-parallel-library

4
推荐指数
1
解决办法
1342
查看次数

标签 统计

.net ×1

c# ×1

exception ×1

task-parallel-library ×1