Skip to main content
edited title
Source Link
Backs
  • 25k
  • 5
  • 66
  • 92

Await and AsynchAsync usage

The MSDN documentation for await and asynchasync gives the following simple example.

async Task<int> AccessTheWebAsync() { HttpClient client = new HttpClient(); Task<string> getStringTask = client.GetStringAsync("http://msdn.microsoft.com"); DoIndependentWork(); string urlContents = await getStringTask; return urlContents.Length; } 

It then states:

If AccessTheWebAsync doesn't have any work that it can do between calling GetStringAsync and awaiting its completion, you can simplify your code by calling and awaiting in the following single statement.

string urlContents = await client.GetStringAsync(); 

But if there is no work to be done between calling the method and its completion what are the benefits of making this method asynchronous?

Await and Asynch usage

The MSDN documentation for await and asynch gives the following simple example.

async Task<int> AccessTheWebAsync() { HttpClient client = new HttpClient(); Task<string> getStringTask = client.GetStringAsync("http://msdn.microsoft.com"); DoIndependentWork(); string urlContents = await getStringTask; return urlContents.Length; } 

It then states:

If AccessTheWebAsync doesn't have any work that it can do between calling GetStringAsync and awaiting its completion, you can simplify your code by calling and awaiting in the following single statement.

string urlContents = await client.GetStringAsync(); 

But if there is no work to be done between calling the method and its completion what are the benefits of making this method asynchronous?

Await and Async usage

The MSDN documentation for await and async gives the following simple example.

async Task<int> AccessTheWebAsync() { HttpClient client = new HttpClient(); Task<string> getStringTask = client.GetStringAsync("http://msdn.microsoft.com"); DoIndependentWork(); string urlContents = await getStringTask; return urlContents.Length; } 

It then states:

If AccessTheWebAsync doesn't have any work that it can do between calling GetStringAsync and awaiting its completion, you can simplify your code by calling and awaiting in the following single statement.

string urlContents = await client.GetStringAsync(); 

But if there is no work to be done between calling the method and its completion what are the benefits of making this method asynchronous?

Source Link
DavidB
  • 2.6k
  • 3
  • 35
  • 66

Await and Asynch usage

The MSDN documentation for await and asynch gives the following simple example.

async Task<int> AccessTheWebAsync() { HttpClient client = new HttpClient(); Task<string> getStringTask = client.GetStringAsync("http://msdn.microsoft.com"); DoIndependentWork(); string urlContents = await getStringTask; return urlContents.Length; } 

It then states:

If AccessTheWebAsync doesn't have any work that it can do between calling GetStringAsync and awaiting its completion, you can simplify your code by calling and awaiting in the following single statement.

string urlContents = await client.GetStringAsync(); 

But if there is no work to be done between calling the method and its completion what are the benefits of making this method asynchronous?