问题描述
我想知道是否有与使用链接到一个或多个ActionBlocks,比(使用BoundedCapacity)节流之外的BufferBlock相关的利益,而不是只直接张贴到ActionBlock(S)(只要是不需要限制)。
I was wondering if there are benefits associated with using a BufferBlock linked to one or many ActionBlocks, other than throttling (using BoundedCapacity), instead of just posting directly to ActionBlock(s) (as long as throttling is not required).
推荐答案
如果你想要做的就是转发来自一个街区项目几个人,你不需要 BufferBlock
。
If all you want to do is to forward items from one block to several others, you don't need BufferBlock
.
不过,当然也有地方是有用的情况。例如,如果你有一个复杂的网络数据流,您可能希望从较小的子网络构建它,在它自己的方法创建的每一个。而要做到这一点,你需要一些方法来表示一组块。在这种情况下,你所提到的,返回单个 BufferBlock
(可能为 ITargetBlock
)的方法将是一个简单的解决方案。
But there are certainly cases where it is useful. For example, if you have a complex dataflow network, you might want to build it from smaller sub-networks, each one created in its own method. And to do this, you need some way to represent a group of blocks. In the case you mentioned, returning that single BufferBlock
(probably as ITargetBlock
) from the method would be an easy solution.
另外一个例子,其中 BufferBlock
将是有益的是,如果你想从多个源块内容发送至多个目标块。如果你使用 BufferBlock
作为中介,你不必给每个源块到每个目标块连接。
Another example where BufferBlock
would be useful is if you wanted to send items from several source blocks to several target blocks. If you used BufferBlock
as an intermediary, you don't have to connect each source block to each target block.
我敢肯定,有许多其他的例子,你可以使用 BufferBlock
。当然,如果你没有看到任何理由在你的情况来使用它,那就不要。
I'm sure there are many other examples where you could use BufferBlock
. Of course, if you don't see any reason to use it in your case, then don't.
这篇关于T>使用BufferBlock<的好处;在网络数据流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!