InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

.NET 4 Cancellation Framework

Posted by Al Tenhundfeld on Jun 03, 2009

Sections
Architecture & Design,
Development,
Enterprise Architecture
Topics
Transactions Processing ,
.NET ,
.NET Framework
Tags
.NET Framework 4.0 ,
Parallel Programming

.NET 4 will have new types to support building cancellation-aware applications and libraries. The new CancellationToken, CancellationTokenSource, and cancellation exception types provide a cooperative cancellation framework.

the motivating principles that the new types were designed to support:

  • any unit of work is commenced, it should have a consistent means to support early termination in response to a cancellation request.
  • If some unit of work controls various other moving pieces, it should be able to conveniently chain cancellation requests to them.
  • Blocking calls should be able to support cancellation.
  • Calls to complex operations, such as MoveNext() on a PLINQ
  • enumerator, should have simple yet comprehensive cancellation support.
  • When infrastructure makes calls back to potentially long-running user code, it should be possible for the user code to observe and respond to cancellation requests in a cooperative fashion.
  • Cancellation should be an obvious part of an API with clean and consistent semantics.
  • Cancellation should not be forceful but instead cooperative.

The framework is built upon two new types:

  • CancellationToken
  • a struct that represents a ‘potential request for cancellation’. This struct is used as an argument to allow methods to poll on it or register a callback to be fired when cancellation is requested.
  • CancellationTokenSource
  • a class that provides the mechanism for initiating a cancellation request. It also provides an association to the related token. This design allows separation of the the two primary cancellation operations: initiating a cancellation request & observing and responding to cancellation. Specifically, methods that accept only a CancellationToken can observe a cancellation request but cannot initiate one.

These new .NET 4 cancellation types provide a framework for building systems that have robust and consistent cancellation behaviors. This will specifically assist with GUIs, applications, and libraries that manage long running or blocking operations. The long-term goal is to reduce the variation and inconsistencies in the current offering of 3rd-party cancellation solutions. These new types will also offer a uniform contract to interoperate with Parallel Extensions.

No comments

Watch Thread Reply

Educational Content

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.