I understand that a BlockingCollection
is best suited for a consumer/producer pattern. However, when do I use a ActionBlock
from the TPL DataFlow library?
My initial understanding is for IO operations, keep the BlockingCollection
while CPU intensive operations are bested suited for an ActionBlock
. But I feel like this isn't the whole story... Any additional insight?
TPL Dataflow is better suited for an actor based design. That means that if you want to chain producers and consumers it's much easier with TDF.
Another big plus for TPL dataflow is that it was built with async
in mind. You can both produce and consume in a synchronous way and in an async
way (and both at the same time), which is very useful.
(I mostly produce in a synchronous way and consume in a non-blocking async
way).
You can also very easily set a bounded capacity and degree of parallelism.
TL;DR: BlockingCollection
is a simple and general tool. TPL Dataflow
is much more robust, but can be an overkill or a bad fit for specific problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With