This post was migrated from Justin’s personal blog, '' Views, opinions, and colorful expressions should be taken in context, and do not necessarily represent those of Simple Thread (and were written under the influence of dangerous levels of caffeination).

One of my favorite quotes is by David Wheeler:

Any problem in computer science can be solved with another layer of indirection.

While this quote is certainly true, problems can arise when the layer of abstraction becomes too heavy. In .NET 2.0 the ThreadPool was introduced and it gave developers a very heavy abstraction over threads. It optimized the execution of multiple threads, but at the same time the developer was abstracted away from the individual threads so much that they lost a significant amount of control.

In .NET 4.0 the Parallel Extensions to .NET are now integrated into the core framework. This means that in the next version of Visual Studio we are going to get all of the new parallel programming features by default. One of these new features is the Task Parallel Library. This feature is a set of classes, called Tasks, which allow us to fire off actions asynchronously.

It looks something like this:

Task task = Task.Create(n => LongRunningMethod(test));

You might be looking at that and saying to yourself, “well, they just reinvented threads and called them tasks”. Well, that isn’t really the case. For example, the following two chunks of code are quite different:

Leave a Reply

Your email address will not be published. Required fields are marked *