2

For example a scenario in Winform where the UI thread will be blocked while we use HttpWebRequest synchronously which in turn requests resources on Internet. Here we can use async method to execute the method while await keyword for certain task allows user to interact with winform even though the request is still running.

This can even be achieved by delegation so what's the advantage of Async Feature?

Rudi Visser
  • 21,350
  • 5
  • 71
  • 97
mvm_bgm
  • 153
  • 1
  • 11

3 Answers3

0

The async and await termonoligy is much simpler and you can basicaly write your code just as you would do a syncronious application by just adding some keywords.

From MSDN:

You can avoid performance bottlenecks and enhance the overall responsiveness of your application by using asynchronous programming. However, traditional techniques for writing asynchronous applications can be complicated, making them difficult to write, debug, and maintain.

Visual Studio 2012 introduces a simplified approach, async programming, that leverages asynchronous support in the .NET Framework 4.5 and the Windows Runtime. The compiler does the difficult work that the developer used to do, and your application retains a logical structure that resembles synchronous code. As a result, you get all the advantages of asynchronous programming with a fraction of the effort.

http://msdn.microsoft.com/en-us/library/vstudio/hh191443.aspx

Moriya
  • 7,750
  • 3
  • 35
  • 53
0

One of the nicest advantages in my opinion is a more concise way to understand the async programming pattern with less lines of code. If you want to see more clearly how it works, check out this question answered by Jon Skeet: How does Task<int> become a int?

Community
  • 1
  • 1
Freeman
  • 5,691
  • 3
  • 29
  • 41
0

I assume by "delegation" you mean to call the synchronous methods from a background thread.

As others have pointed out, the code is easier to read and write using async and await, but there's another important difference as well.

When you use synchronous methods, the calling thread is blocked until the operation is complete.

When you use synchronous methods from a background thread, the UI thread is not blocked but the background thread still is.

When you use asynchronous methods, no threads are blocked. This allows more efficient usage of your resources, with less pressure on the thread pool.

Stephen Cleary
  • 437,863
  • 77
  • 675
  • 810