| Start |
|---|
| ActionBlock (foreach) This class can be thought of logically as a buffer for data to be processed combined with tasks for processing that data, with the “dataflow block” managing both. In its most basic usage, we can instantiate an ActionBlock and “post” data to it; the delegate provided at the ActionBlock’s construction will be executed asynchronously for every piece of data posted. Synchronous Computation Throttling Asynchronous Downloads to at most 5 concurrently Introduction to TPL Dataflow by Stephen Toub (opens new window) |
| BroadcastBlock (Copy an item and send the copies to every block that it’s linked to) Unlike BufferBlock, BroadcastBlock’s mission in life is to enable all targets linked from the block to get a copy of every element published, continually overwriting the “current” value with those propagated to it. Additionally, unlike BufferBlock, BroadcastBlock doesn’t hold on to data unnecessarily. After a particular datum has been offered to all targets, that element will be overwritten by whatever piece of data is next in line (as with all dataflow blocks, messages are handled in FIFO order). That element will be offered to all targets, and so on. Asynchronous Producer/Consumer with a Throttled Producer Exposing Status from an Agent Introduction to TPL Dataflow by Stephen Toub (opens new window) |
| BufferBlock (FIFO Queue: The data that comes in is the data that goes out) In short, BufferBlock provides an unbounded or bounded buffer for storing instances of T. Asynchronous Producer/Consumer with a Throttled Producer Introduction to TPL Dataflow by Stephen Toub (opens new window) |
| JoinBlock<T1, T2,…> (Collects 2-3 inputs and combines them into a Tuple) Like BatchBlock, JoinBlock<T1, T2, …> is able to group data from multiple data sources. In fact, that’s JoinBlock<T1, T2, …>’s primary purpose. For example, a JoinBlock<string, double, int> is an ISourceBlock<Tuple<string, double, int>>. As with BatchBlock, JoinBlock<T1, T2,…> is capable of operating in both greedy and non-greedy mode.
Processing Requests with a Limited Number of Pooled Objects Introduction to TPL Dataflow by Stephen Toub (opens new window) |
| WriteOnceBlock (Readonly variable: Memorizes its first data item and passes out copies of it as its output. Ignores all other data items) If BufferBlock is the most fundamental block in TPL Dataflow, WriteOnceBlock is the simplest. You can think of WriteOnceBlock in as being similar to a readonly member variable in C#, except instead of only being settable in a constructor and then being immutable, it’s only settable once and is then immutable. Splitting a Task’s Potential Outputs Introduction to TPL Dataflow by Stephen Toub (opens new window) |
| BatchedJoinBlock<T1, T2,…> (Collects a certain number of total items from 2-3 inputs and groups them into a Tuple of collections of data items) BatchedJoinBlock<T1, T2,…> is in a sense a combination of BatchBlock and JoinBlock<T1, T2,…>. Scatter/Gather Consider a scatter/gather problem where N operations are launched, some of which may succeed and produce string outputs, and others of which may fail and produce Exceptions. Introduction to TPL Dataflow by Stephen Toub (opens new window) |
| TransformBlock<TInput, TOutput> (Select, one-to-one) As with ActionBlock, TransformBlock<TInput, TOutput> 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<TInput, TOutput>, in which case processing of that element is considered completed when the delegate returns, or it can be a Func<TInput,Task>, 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<TInput, TOutput> processes its data sequentially with a MaxDegreeOfParallelism equal to 1. In addition to receiving buffered input and processing it, this block will take all of its processed output and buffer 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 Introduction to TPL Dataflow by Stephen Toub (opens new window) |
| TransformManyBlock<TInput, TOutput> (SelectMany, 1-m: The results of this mapping are “flattened”, just like LINQ’s SelectMany) TransformManyBlock<TInput, TOutput> is very similar to TransformBlock<TInput, TOutput>. A Func<TInput, IEnumerable> is used for synchronous, and a Func<TInput, Task The mapping delegate retuns a collection of items, which are inserted individually into the output buffer. Asynchronous Web Crawler Expanding an Enumerable Into Its Constituent Elements Filtering by going from 1 to 0 or 1 elements Introduction to TPL Dataflow by Stephen Toub (opens new window) |
| BatchBlock (Groups a certain number of sequential data items into collections of data items) BatchBlock combines N single items into one batch item, represented as an array of elements. An instance is created with a specific batch size, and the block then creates a batch as soon as it’s received that number of elements, asynchronously outputting the batch to the output buffer. BatchBlock is capable of executing in both greedy and non-greedy modes.
Batching Requests into groups of 100 to Submit to a Database Creating a batch once a second Introduction to TPL Dataflow by Stephen Toub (opens new window) |
Read Article
https://develop.horje.com/learn/1434/reference