Thursday, October 28, 2010

Asynchrony Await and the Async CTP

More Asynchrony in programming to look forward to. And for users it means more responsive and quicker applications.

Async CTP introduces a new keyword await, which indicates that the caller would like control to return when an asynchronous method call has completed. And the Async modifier does not create additional threads.

public async Task<int> SumPageSizesAsync(IList<Uri> uris) { int total = 0; foreach (var uri in uris) { statusText.Text = string.Format("Found {0} bytes ...", total); var data = await new WebClient().DownloadDataTaskAsync(uri); total += data.Length; } statusText.Text = string.Format("Found {0} bytes total", total); return total; }

Public Async Function SumPageSizesAsync(uris As IList(Of Uri)) As Task(Of Integer) Dim total As Integer = 0 For Each uri In uris statusText.Text = String.Format("Found {0} bytes ...", total) Dim data = Await New WebClient().DownloadDataTaskAsync(uri) total += data.Length Next statusText.Text = String.Format("Found {0} bytes total", total) Return total End Function

Making Asynchronous Programming Easy

Asynchrony in C# 5, Part One

Announcing the Async CTP for Visual Basic (and also Iterators!)

The async CTP homepage: http://msdn.com/vstudio/async

No comments:

Post a Comment

Some of the latest blog posts

Subscribe to RSS headline updates from:
Powered by FeedBurner

Contact Us | About JTB World | Website General Terms of Use | Privacy Policy
^ Top of page

© 2004- JTB World. All rights reserved.