Benefits of using BufferBlock<T> in dataflow networks

Dimitri picture Dimitri · Oct 8, 2012 · Viewed 12.3k times · Source

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).

Answer

svick picture svick · Oct 8, 2012

If all you want to do is to forward items from one block to several others, you don't need BufferBlock.

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.

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.

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.