title: Task.Run vs. ContinueWith in ASP.NET MVC
body: <p>In my ASP.NET MVC 4 application, say I have some <code>async</code> method:</p>
  
  <pre><code>async Task DoSomeBackgroundWork()
  {
     // Fake it
     await Task.Delay(5000);
  }
  </code></pre>
  
  <p>Now, one can call this method like this:</p>
  
  <pre><code>Task.Run(async () =&gt; 
  {
    await DoSomeBackgroundWork();
    Debug.WriteLine("Background work finished");
  });
  </code></pre>
  
  <p>or this:</p>
  
  <pre><code>DoSomeBackgroundWork()
    .ContinueWith(t =&gt; Debug.WriteLine("Background work finished"));
  </code></pre>
  
  <p>Note that in both versions the caller doesn't wait for the background task to finish. It's just fire and forget.</p>
  
  <p>While both versions work identical (ignore exception handling here) on regular .NET apps, on a MVC app, <em>when calling the code from a MVC controller method</em>, <code>Debug.WriteLine</code> is only executed in the <code>Task.Run</code> version - but not in the <code>ContinueWith</code> version.</p>
  
  <p><strong>Can anyone shed some light onto why these two versions are working differently when called in a MVC controller method?</strong></p>