In addition to Monroe Thomas's answer, it is important to understand that the ActionBlock following BroadcastBlock needs Limited bandwidth, limited to 1 , or it will store and process each broadcast block message, even if it is still running.
Sample code is given here:
ActionBlock<int> ExecuteBlock = new ActionBlock<int>(async ThisNumber => { await Task.Delay(100); Console.WriteLine($">{ThisNumber}"); }, new ExecutionDataflowBlockOptions { BoundedCapacity = 1 }); BroadcastBlock<int> ThrottleBlock = new BroadcastBlock<int>(null); ThrottleBlock.LinkTo(ExecuteBlock, new DataflowLinkOptions { PropagateCompletion = true }); for(int IX = 0; IX < 128; IX++) { await ThrottleBlock.SendAsync(IX); await Task.Delay(10); }
The result is the following:
>0 >6 >12 >20 >27 >34 >41 >48 >55 >62 >68 >75 >82 >88 >95 >101 >108 >115 >122 >127
Enjoy it!
-Simon
Simon mattes
source share