Endjin - Home

TPL Dataflow by Example code samples for LINQPad

by Howard van Rooijen

Reactive Programming and in particular Task Parallel Library Dataflow has been on my radar for a number of years after reading  Stephen Toub’sIntroduction to TPL Dataflow” whitepaper and watching his Channel9 videos (TPL Dataflow Tour, Inside TPL Dataflow). Unfortunately all of my research time of late has been absorbed trying to keep up with the rapidly changing Microsoft Azure ecosystem, until over the Christmas period I finally got the chance to consume both of Matt Carkci’s excellent books on the subject:


Dataflow and Reactive Programming Systems: A Practical Guide


TPL Dataflow by Example: Dataflow and Reactive Programming in .Net

Dataflow & Reactive Programming Systems is a more detailed overview of the theory of the dataflow and reactive paradigms (with examples in Haskell), whereas TPL Dataflow by example is a step by step guide of how the paradigms have been implemented in the .NET ecosystem with TPL Dataflow.

TPL Dataflow by Example does have code samples available, but they are raw .cs files (as the author states there isn’t a “Visual Studio project due to the number of versions of Visual Studio that exist”). I decided on a slightly different approach – I’ve been a fan of LINQPad for a number of years as one of it’s really neat features is the Samples Library that enables you to create a collection of code samples – a feature that has been used by many book authors for publishing their code samples.

First download the TPL Dataflow by Example sample file.

Next, open LINQPad, select the “Samples” tab and click the “Download / Import more samples” link:


This will pop open the Browse Sample Libraries window. Select the browse link, navigate to and select the sample file you just downloaded:


Now you should see the new “TPL Dataflow by Example – Matt Carkci” folder with a list of files:


You should be able to just press the run button, the required TPL Dataflow NuGet package should automatically download, then the code sample should run.

I’ve made a few structural changes to the original code samples in order to make them run in LINQPad, otherwise everything else should be the same. Hopefully if you’re interested in Dataflow & have purchased the book, this might help you run through the examples more easily.

Creating a sample library is very simple – follow these instructions to make your own.

Update: Joe Albahari points out that LINQPad actually supports Dataflow block:


@HowardvRooijen | @endjin

About the author

Howard spent 10 years as a technology consultant helping some of the UK's best known organisations work smarter, before founding endjin in 2010. He's a Microsoft Accelerator Mentor, and a Microsoft Azure MVP. You can follow him on Twitter via @HowardvRooijen