BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Resources On Async Tasks

Resources On Async Tasks

This item in japanese

Async Tasks, included in the Task Parallel Library, is a great way to write asynchronous code in – we look at a few resources that show how to use this API in different scenarios and what are the various considerations.

In the article “Enabling Progress And Cancellation in Async APIs” Brandon Bay shows how to create keep a Progress Bar updated while uploading a file asynchronously. You can also use the cancellation token to allow the user to cancel an async task. In an earlier article, Brandon shows the difference between the earlier methods of writing asynchronous code (through EAP and APM) and the new way through async and await keywords. This FAQ on Async/Await also gets into more details and points to more resources. 

While asynchronous programming becomes much simpler with the new key words, developers should avoid going over-board in using them – async calls can be expensive and it is better to make few large async calls over lots of small ones.

Use of Async is not limited to Windows Programming, and it can be used in ASP.NET server-side code as well. Task Support For Async Controllers, introduced in ASP.NET MVC 4, makes it much easier to write non-blocking code in controllers which can further use asynchronous methods themselves. You can even set timeouts and raise exceptions when a timeout does occur. Note though, that this is supported only with C# 5.

It's worth noting, that the async and await keywords are so convenient that at least one node.js fork is already experimenting with the syntax as an alternative to traditional callbacks in javascript.

Rate this Article

Adoption
Style

Educational Content

BT