Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>No, <code>await</code> is <em>not</em> like just calling <code>get()</code>. There's <em>considerably</em> more to it.</p> <p>When you use an <code>await</code> expression in C#, the compiler effectively creates a continuation, so that if the awaitable hasn't completed yet, the method can immediately return, and continue processing only when it's completed. The continuation will run in an appropriate context - so if you're on a UI thread before the <code>await</code> expression, you'll continue on the UI thread afterwards, but without blocking the UI thread while you're waiting for the result. For example:</p> <pre><code>public async void HandleButtonClick(object sender, EventArgs e) { // All of this method will run in the UI thread, which it needs // to as it touches the UI... however, it won't block when it does // the web operation. string url = urlTextBox.Text; WebClient client = new WebClient(); string webText = await client.DownloadStringTaskAsync(url); // Continuation... automatically called in the UI thread, with appropriate // context (local variables etc) which we used earlier. sizeTextBox.Text = string.Format("{0}: {1}", url, webText.Length); } </code></pre> <p>Ultimately it's all syntactic sugar, but <em>much</em> more complicated sugar than what you've shown.</p> <p>There's a lot of detailed information available on the web already. For example:</p> <ul> <li><a href="http://blogs.msdn.com/b/ericlippert/archive/tags/async/" rel="nofollow noreferrer">Eric Lippert's blog</a></li> <li>The <a href="http://msdn.microsoft.com/en-us/vstudio/gg316360" rel="nofollow noreferrer">Visual Studio async home page</a></li> <li><a href="https://codeblog.jonskeet.uk/category/async/" rel="nofollow noreferrer">My own blog posts about async</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload