TPL Dataflow, guarantee completion only when ALL source data blocks completed

前端 未结 5 1098
谎友^
谎友^ 2020-12-08 19:54

How can I re-write the code that the code completes when BOTH transformblocks completed? I thought completion means that it is marked complete AND the \" out queue\" is empt

5条回答
  •  无人及你
    2020-12-08 20:47

    The issue is exactly what casperOne said in his answer. Once the first transform block completes, the processor block goes into “finishing mode”: it will process remaining items in its input queue, but it won't accept any new items.

    There is a simpler fix than splitting your processor block in two though: don't set PropagateCompletion, but instead set completion of the processor block manually when both transform blocks complete:

    Task.WhenAll(transformBlock1.Completion, transformBlock2.Completion)
        .ContinueWith(_ => processorBlock.Complete());
    

提交回复
热议问题