JoinBlock C# with Example
(Collects 2-3 inputs and combines them into a Tuple) Like BatchBlock, JoinBlock is able to group data from multiple data sources. In fact, that ’s JoinBlock ’s primary purpose. For example, a JoinBlock is an ISourceBlock>. As with BatchBlock, JoinBlock is capable of operating in both greedy and non-greedy mode. In the default greedy mode, all data offered to targets are accepted, even if the other target doesn ’t have the necessary data with which to form a tuple. In non-greedy mode, the block ’s targets will postpone data until all targets have been offered the necessary data to create a tuple, at which point the block will engage in a two-phase commit protocol to atomically retrieve all necessary items from the sources. This postponement makes it possible for another entity to consume the data in the meantime so as to allow the overall system to make forward progress. Processing Requests with a Limited Number of Pooled Objects var throttle = new JoinBlock(); for(int i=0; i<10; i++) { requestProcessor.Target1.Post(new ExpensiveObject()); } var processor = new Transform, ExpensiveObject>(pair => { var resource = pair.Item1; var request = pair.Item2; request.ProcessWith(resource); return resource; }); throttle.LinkTo(processor); processor.LinkTo(throttle.Target1); Introduction to TPL Dataflow by Stephen Toub