TransformBlock C# with Example
As with ActionBlock, TransformBlock enables the execution of a delegate to perform some action
for each input datum; unlike with ActionBlock, this processing has an output. This delegate can be a
Func, in which case processing of that element is considered completed when the delegate
returns, or it can be a Func, in which case processing of that element is considered completed not
when the delegate returns but when the returned Task completes. For those familiar with LINQ, it ’s somewhat
similar to Select() in that it takes an input, transforms that input in some manner, and then produces an output.
By default, TransformBlock processes its data sequentially with a MaxDegreeOfParallelism equal
to 1. In addition to receiving buﬀered input and processing it, this block will take all of its processed output and
buﬀer that as well (data that has not been processed, and data that has been processed).
It has 2 tasks: One to process the data, and one to push data to the next block.
A Concurrent Pipeline
var compressor = new TransformBlock(input => Compress(input));
var encryptor = new TransformBlock(input => Encrypt(input));
Introduction to TPL Dataﬂow by Stephen Toub