Processing Sequences of Asynchronous Operations with Tasks

Of late, I’ve seen multiple folks asking about how to use tasks to asynchronously execute a sequence of operations.  For example, given three synchronous functions: public string DoA(string input); public string DoB(string aResult); public string DoC(string bResult); you could invoke these functions with code like: string aResult = DoA(input); string bResult = DoB(aResult); string cResult… Read more

New Feature? :: Delayed cancellation

  We’re interested in adding support for scheduling cancellation.  For example:   // Create a token source that will Cancel() after a delay var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); // And/or schedule a Cancel() call cts.CancelAfter(TimeSpan.FromMilliseconds(100)); We’ve heard from many folks that this is a desired feature and have found good uses for it ourselves.  Interestingly,… Read more

TPL Dataflow preview available for download

As mentioned here, the Visual Studio Async CTP is now available for download from  Not only does this download add language support into C# and Visual Basic for writing asynchronous methods (in which you can easily “await” tasks), it also includes a new .NET library we lovingly refer to as “TPL Dataflow”, which enables… Read more

Language support for Tasks!

Today is a very exciting day for Parallel Extensions, and indeed for all developers using C# and Visual Basic and who are interested in writing more responsive and scalable applications. At the PDC this morning, Anders Hejlsberg just announced the Visual Studio Async CTP, which you can download immediately from the landing page at … Read more

New Feature? :: ThreadLocal<T>.Values

We’ve been considering adding a Values property to System.Threading.ThreadLocal<T>.  Values would return a collection of all current values from all threads (e.g. what you’d get if you evaluated Value from each thread).  This would allow for easy aggregations, and in fact in our Parallel Extensions Extras we have a wrapper around ThreadLocal<T> called ReducationVariable<T> that… Read more

FAQ :: StartNew() with TaskScheduler.FromCurrentSynchronizationContext() doesn’t work?

We’ve seen a number of folks write the following code to execute on the UI thread and get unexpected behavior.   TaskScheduler uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();Task uiTask = Task.Factory.StartNew(delegate{    // … Update UI component; BUG!}, uiScheduler); The issue is that the StartNew call will bind to the following overload…   public Task StartNew(Action<Object> action, Object state);… Read more

Creating pre-completed Tasks

  We’ve been considering adding support for creating completed Tasks from an existing result.  Here’s a prototypical example of where this could be valuable.   void Task<float> ComputeAsync(…) {     if (!resultIsCached)     {         return Task<float>.Factory.StartNew(() => Compute());     }     else     {         // return a Task<float> with the cached result    … Read more

FAQ :: TaskScheduler.UnobservedTaskException event doesn’t work?

Recall that if exceptions thrown from Task bodies are left unobserved, they will be escalated.  In .NET 4, this means that TPL will throw them on the finalizer after the Task objects are available for garbage collection.  The UnobservedTaskException event on the TaskScheduler class was added as a last-resort method to observe such exceptions and… Read more

Microsoft Biology Foundation 1.0 Released

It’s exciting to see that the Microsoft Biology Foundation 1.0 has been released!  You can read more about it here.  From MBF’s Web site: “The Microsoft Biology Foundation (MBF) is a language-neutral bioinformatics toolkit built as an extension to the Microsoft .NET Framework, initially aimed at the area of Genomics research. Currently, it implements a range… Read more