Parallel Dataflow Part 2: Listing 2

The PostProcess Button Click Event Handler.

private void PostProcess_Click(object sender, RoutedEventArgs e)
 {
     const int average = 75;
     TransformBlock<int, int> averageDelta = new TransformBlock<int, int>(x => x - average);
     TransformBlock<int, string> formatPost = new TransformBlock<int, string>(x =>
     {
         string preFix = string.Empty;
         if (x > 0)
             preFix = "+";

         return String.Format("{0}{1:G2}°F", preFix, x);
     });

     ActionBlock<string> postProcessDisplayer = CreateUiUpdateActionBlock<string>(PostProcessMessage);

     _broadcaster.LinkTo(averageDelta);
     averageDelta.LinkTo(formatPost);
     formatPost.LinkTo(postProcessDisplayer);
 }

About the Author

Eric Vogel is a Senior Software Developer for Red Cedar Solutions Group in Okemos, Michigan. He is the president of the Greater Lansing User Group for .NET. Eric enjoys learning about software architecture and craftsmanship, and is always looking for ways to create more robust and testable applications. Contact him at vogelvision@gmail.com.