Cooperatively pausing async methods

Recently I was writing an app that processed a bunch of files asynchronously.  As with the Windows copy file dialog, I wanted to be able to provide the user with a button that would pause the processing operation. To achieve that, I implemented a simple mechanism that would allow me to pass a “pause token”… Read more

Coalescing CancellationTokens from Timeouts

In the .NET Framework 4.5 Developer Preview, you’ll find that CancellationTokenSource now has timeout support built directly into its implementation.  This makes it very easy to create a token that will automatically have cancellation requested after a particular time interval, e.g. public static CancellationToken FromTimeout(int millisecondsDue) {     return new CancellationTokenSource(millisecondsDue).Token; } Under the covers… 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

Using Cancellation Support in .NET Framework 4

The .NET Framework 4 introduces a new mechanism for cancellation of operations, based on new types CancellationToken and CancellationTokenSource. This cancellation mechanism is used across the parallel programming libraries: tasks, concurrent collections, and PLINQ queries. Using Cancellation Support in .NET Framework 4, written by Mike Liddell, is an in-depth exploration of CancellationToken and CancellationTokenSource, how to make… Read more

What’s new in Beta 2 for the Task Parallel Library? (Part 1/3)

Related posts: What’s new in Beta 2 for the Task Parallel Library? (Part 2/3)  What’s new in Beta 2 for the Task Parallel Library? (Part 3/3)  Visual Studio 2010 and .NET 4 Beta 2 is here!  In terms of completeness and readiness for production coding, Beta 2 promises to be much better than Beta 1, and TPL… Read more

Cancellation in Parallel Extensions

One of the great features that crosses all of Parallel Extensions types is a consistent approach to cancellation (see In this post we explore some of the ways cancellation is used in Parallel Extensions and explain the guidance we developed. The new cancellation system is a cooperative approach based on two new types: CancellationTokenSource,… Read more

.NET 4 Cancellation Framework

A very interesting addition to .NET 4 is a set of new types that specifically assist with building cancellation-aware applications and libraries. The new types enable rich scenarios for convenient and safe cancellation, and help simplify situations that used to be be difficult and error-prone and non-composable. The details of the new types are described… Read more