.NET Zone is brought to you in partnership with:

I’ve been a Windows developer since 3.0 and caught the Visual Basic wave early with v1. I’ve released a “production” application in every version of VB since then (except VB for DOS). Focusing on enterprise, line-of-business development I’ve built Call Center Applications, Mortgage finance systems, Customer Relationship Management tools and more recently I’ve been in the Litigation Support/Electronic Data Discovery/Electronically Stored Information space. Greg is a DZone MVB and is not an employee of DZone and has posted 272 posts at DZone. You can read more from them at their website. View Full User Profile

Primer for Task Parallel Library- Task Parallel Dataflow

09.03.2012
| 1690 views |
  • submit to reddit

Visual Studio Magazine - A .NET 4.5 Parallel Dataflow Primer

"The Task Parallel Dataflow (TDF) library is built upon the existing Task Parallel Library (TPL) included in the .NET 4.0 Framework. Although the TPL provides a lot of functionality to help parallelize an application, it doesn't make it overly easy to tackle complex parallel use cases such as consumer/provider and agent-based models.

The TDF, on the other hand, provides higher-level abstractions in the form of  generic code blocks that generate and schedule the needed Task objects to handle simple to complex data flows.

The TDF is still in a preview state; it can be installed in Visual Studio 2012 RC through NuGet, as shown in Figure 1.

...

Once the package is installed, you should see a reference to System.Threading.Tasks.Dataflow in your project, as seen in Figure 2.

In the TDF, all blocks implement the common IDataflowBlock interface. The IDataflowBlock interface contains  Complete and Fault methods, and a Completion property getter. The Complete method is called upon successful completion of the dataflow block's task. The Fault method is invoked if an exception occurs and the Completion property returns the Task that will be executed asynchronously by the dataflow block.

All the dataflow blocks also implement either the ISourceBlock<T> or ITargetBlock<T> interface, or both. The ISourceBlock<T> interface defines a contract for offering data, whereas the ITargetBlock<T> interface defines an interface for receiving data.

The ActionBlock
I'll begin with the ActionBlock, which implements the ITargetBlock<T> interface. In turn, the ISourceBlock and ITargetBlock interfaces both inherit the base IDataflowBlock interface. Later I'll go over the TransformBlock  that implements both the ISourceBlock and ITargetBlock interfaces

..."

This looks like a good introduction and primer for the TDF. If you've heard of it but haven't looked into yet, this two page article will help you know what you don't know.
Published at DZone with permission of Greg Duncan, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)