TPL Dataflow and async/await vs CCR – part 6

Same co-worker as the other day pointed out an important difference between how CCR and TPL data flow deals with exclusive schedulers as described in the end of part 4. To illustrate, assume you have the following test code: 1: [TestMethod] 2: public void TestExclusiveExecution() 3: { 4: var options = new ExecutionDataflowBlockOptions() 5: {…

0

TPL Dataflow and async/await vs CCR – part 5

I got a tip from a co-worker that your choice of waiting for a scatter gather operation as described in part 3 may have a huge performance impact. I made three version of the FibonacciAsync, one that awaits on the return statement, one that uses the Task.WaitAll method and one that just awaits each call…

2

TPL Dataflow and async/await vs CCR – summary

As you have seen there is really much less to cover when doing “CCR tips & tricks for TPL data-flow” probably mostly because the latter is about seven years younger and designed with a latest and greatest in mind. While you tend to need to do a lot of work yourself with CCR for certain scenarios TPL data-flow…

0

TPL Dataflow and async/await vs CCR – part 4

Today I wanted to show a number of simple examples of how to do things with TPL data-flow compared to CCR. Creating a CCR port and posting and then receiving on it asynchronously is one fundamental scenario in CCR. This is what it looks like with TPL data-flow: 1: var port = new BufferBlock<int>(); 2:…

1

TPL Dataflow and async/await vs CCR – part 3

While you could use TPL data-flow for scatter/gather patterns in much the same way as CCR async/await is actually enough for you once again. The only thing you need to do is to create a number of tasks and then wait for them all either by using the Task.WaitAll method (or Task.WaitAny if you’re only…

1

TPL Dataflow and async/await vs CCR – part 2

Dealing with asynchronous APIs will also be much easier than with CCR. First of all you can expect most (if not all) classes in the .Net framework to have another method added to them that is declared async. For example the Stream object used to have a synchronous Read method and then BeginRead and EndRead…

4

TPL Dataflow and async/await vs CCR – part 1

As when working with CCR, working with async/await you need to have good tools for writing tests and execute the asynchronous code synchronously. I wish it was this easy: 1: [TestMethod] 2: public async void WithAsync() 3: { 4: Assert.AreEqual(42, await DoSomething()); 5: } Unfortunately this does not work and I hope it changes before the next…

1

TPL Dataflow and async/await vs CCR – Introduction

In the .Net framework 4.5 developer preview there are two new great additions; TPL data-flow classes and async/await keywords. If you’re familiar with CCR you’ll notice that TPL data-flow looks and feels a lot like CCR. The new async/await keywords also make asynchronous programming very easy. So I sat down and revisited my old CCR tips…

1

Dependency injection and good design

I helped preparing a meeting on dependency injection on my team and we had that meeting last week and it lead to a number of interesting discussions. Before we go into that I have to explain the title (which was the same as the title for this blog post). If you look at attributes people…

0

ForEach enumeration with index

Yesterday I did a code review that used a pattern I’ve seen a couple of times in the past. The pattern is using a foreach statement to enumerate over some collection but doing things where an index variable is important. This is typically done when working with an enumerable and where the cost to convert…

1