x Share your thoughts on trends and content!

New Asynchronous Features Enhance .NET Framework 4.5

by on Apr 11, 2012 |

Developers who have had the opportunity to try out Visual Studio 11 or the Visual Studio Async CTP may be familiar with the new keywords Await and Async in Visual Basic and C#. Recently, Microsoft detailed some of the new changes in .NET Framework 4.5 that will further extend asynchronous programming capabilities.

Writing asynchronous code has become significantly easier in .NET 4.5, and will no longer require very complex methods or callbacks. The structure of new async tasks will look quite familiar to developers; here’s an example of a synchronous method declaration and its asynchronous counterpart:

'synchronous method
Private Function GetInfo(url As String) As Byte()

'asynchronous method
Private Async Function GetInfo(url As String) As Task(Of Byte())

Asynchronous methods return a task; when Await is called against that task, the method is immediately suspended, and resumes once the task is complete. The structure is simple, but implementing asynchronous code requires a great deal more consideration to avoid decreasing performance.

In addition to the C# and Visual Basic language changes, .NET Framework 4.5 Developer Preview adds a collection of asynchronous methods for common operations. System.IO now includes methods such as ReadAsync, WriteAsync, CopyToAsync, and a few others. Many of the methods in System.Data.Common and System.Data.SqlClient have accompanying asynchronous versions, such as ExecuteQueryAsync, ExecuteScalarAsync, and ReadAsync.

ASP.NET 4.5 allows developers to use HttpRequest.GetBufferlessInputStream asynchronously, and introduces the HttpTaskAsyncHandler to make it easier to write asynchronous handlers and utilize tasks. Windows Communication Foundation (WCF) and Windows Presentation Foundation (WPF) include new asynchronous features as well.

To get started with the new asynchronous features in .NET Framework 4.5 Beta, visit Visual Studio Asynchronous Programming. The framework is available as part of Visual Studio 11, or via the Async CTP for Visual Studio 2010.

Rate this Article


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

General Feedback
Marketing and all content copyright © 2006-2016 C4Media Inc. hosted at Contegix, the best ISP we've ever worked with.
Privacy policy

We notice you're using an ad blocker

We understand why you use ad blockers. However to keep InfoQ free we need your support. InfoQ will not provide your data to third parties without individual opt-in consent. We only work with advertisers relevant to our readers. Please consider whitelisting us.