I just started to learn about TPL Dataflow and have a question as described below:

"Block"s 1, 2, 3 holds references to states. They modify the states and send messages downstream each time they receive a message. The number of such blocks varies.
The "Aggregator" receives messages from the Blocks and check all the messages for errors. After all source blocks are Completed and aggregator passes a single message to the "Releaser".
"Releaser" holds a reference to the state. It will know from "Aggregator" whether the updating is done correctly and will send the state with a success message or a failure message downstream.
public static void Run() { var sourceBlock1 = new TransformBlock<int, int>(x => x * 2); var sourceBlock2 = new TransformBlock<int, int>(x => x * 3); //How to implement the aggregator that aggregates messages from an unknown number of sources and then return a message //when all sources are complete? var aggregater = new TransformBlock<int, int[]>(x => ?); var releaser = new TransformBlock<int[], int>(xs => xs.Sum()); sourceBlock1.LinkTo(aggregater); sourceBlock2.LinkTo(aggregater); aggregater.LinkTo(releaser); sourceBlock1.Post(10); sourceBlock2.Post(20); targetBlock.Completion.Wait(); }
In this line:
...the
aggregaterreceives no notification that it has become the linked target of thesourceBlock1. TheISourceBlock<TOutput>.LinkTomethod changes only the state of the source, not the target. The target will only become aware that it has been linked when it is offered the first message, via theITargetBlock<TInput>.OfferMessagemethod:Even then, it's not guaranteed that the
sourceargument will be a reference to thesourceBlock1, since thesourceBlock1can opt to intercept an internal proxyISourceBlock<TInput>implementation between itself and its linked target. So I don't think that you can achieve what you want using solely the methods of the existing interfaces. Maybe you could equip your custom aggregator block with an API that allows for bidirectional link-awareness. For example:As for how to propagate the completion of multiple blocks to a single target block, take a look at these links: