title: What are the differences between using ConfigureAwait(false) and Task.Run?
body: <p>I understand that it's recommended to use <code>ConfigureAwait(false)</code> for <code>await</code>s in library code so that subsequent code does not run in the caller's execution context, which could be a UI thread. I also understand that <code>await Task.Run(CpuBoundWork)</code> should be used instead of <code>CpuBoundWork()</code> for the same reason.</p>
  
  <h2>Example with <code>ConfigureAwait</code></h2>
  
  <pre><code>public async Task&lt;HtmlDocument&gt; LoadPage(Uri address)
  {
      using (var client = new HttpClient())
      using (var httpResponse = await client.GetAsync(address).ConfigureAwait(false))
      using (var responseContent = httpResponse.Content)
      using (var contentStream = await responseContent.ReadAsStreamAsync().ConfigureAwait(false))
          return LoadHtmlDocument(contentStream); //CPU-bound
  }
  </code></pre>
  
  <h2>Example with <code>Task.Run</code></h2>
  
  <pre><code>public async Task&lt;HtmlDocument&gt; LoadPage(Uri address)
  {
      using (var client = new HttpClient())
      using (var httpResponse = await client.GetAsync(address))
          return await Task.Run(async () =&gt;
          {
              using (var responseContent = httpResponse.Content)
              using (var contentStream = await responseContent.ReadAsStreamAsync())
                  return LoadHtmlDocument(contentStream); //CPU-bound
          });
  }
  </code></pre>
  
  <p>What are the differences between these two approaches?</p>