Resources On Async Tasks
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.
No need to branching node.js