完成TPL数据流链 [英] Completing a TPL dataflow chain
本文介绍了完成TPL数据流链的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出以下代码:
s_Batch = new BatchBlock<PerformanceRecord>(500);
s_Action = new ActionBlock<PerformanceRecord[]>(a => SendToDatabase(a));
s_Batch.LinkTo(s_Action);
完成后,是否需要在每个块上调用 Complete()
?还是完成 s_Batch
会在与其链接的块中触发完成?
When I'm done do I need to call Complete()
on each block? Or will completing s_Batch
trigger a complete in the blocks linked to it?
推荐答案
按照您的代码现在的样子,您需要在所有块上分别调用 Complete
:
As your code stands now, you need to call Complete
on all blocks individually:
s_Batch.Complete();
await s_Batch.Completion;
s_Action.Complete();
await s_Action.Completion;
但是,在链接这些块以请求完成传播时,您可以使用 DataflowLinkOptions
:
You could however use DataflowLinkOptions
while linking the blocks to request completion propagation:
s_Batch.LinkTo(s_Action, new DataflowLinkOptions {PropagateCompletion = true});
s_Batch.Complete();
await s_Batch.Completion;
这会将完成和故障通知传播到链接的目标块(即 s_Action
).
This will propagate both completion and faulting notification to the linked target block (i.e. s_Action
).
这篇关于完成TPL数据流链的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文