Async methods and awaiting in detail

It is important to understand that async methods like SumPageSizesAsync do not run on their own thread. In fact if you write an async method without any await’s in it, it will be completely synchronous: public async Task<int> TenToSevenAsync() { Thread.Sleep(10000); return 7; } Public Async Function TenToSevenAsync() As Task(Of Integer) Thread.Sleep(10000) Return 7 End

Whats New in C# 5.0 Part-2

With the proposed new features, the asynchronous version of the code will instead look like this: 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().DownloadDataAsync(uri); total += data.Length; } statusText.Text = string.Format(“Found {0} bytes total”,