Search code examples
c#.net-4.5async-await

Brief explanation of Async/Await in .Net 4.5


How does Asynchronous tasks (Async/Await) work in .Net 4.5?

Some sample code:

private async Task<bool> TestFunction()
{
  var x = await DoesSomethingExists();
  var y = await DoesSomethingElseExists();
  return y;
}

Does the second await statement get executed right away or after the first await returns?


Solution

  • await pauses the method until the operation completes. So the second await would get executed after the first await returns.

    For more information, see my async / await intro or the official FAQ.