title: Background started task does not finish/gets terminated after the first encountered await
body: <p>In an ASP.NET application, I have an action which when hit, starts a new background task in the following way: </p>
  
  <pre><code>Task.Factory.StartNew(async () =&gt; await somethingWithCpuAndIo(input), CancellationToken.None, TaskCreationOptions.DenyChildAttach | TaskCreationOptions.LongRunning, TaskScheduler.FromCurrentSynchronizationContext());
  </code></pre>
  
  <p>I'm not awaiting it, I just want it to start, and continuing doing its work in the background.
  Immediately after that, I return a response to the client.</p>
  
  <p>For some reason though, after the initial thread executing the background work hits an await that awaits the completion of a method, when debugging, I successfully resolve the method, but upon returning, execution just stops and does not continue below that point.</p>
  
  <p>Interestingly, if I fully await this task (using double <code>await</code>), everything works as expected.</p>
  
  <p>Is this due to the SynchronizationContext? The moment I return a response, the synchronizationContext is disposed/removed? (The SynchronizationContext is being used inside the method)</p>
  
  <p>If it is due to that, where exactly does the issue happen?</p>
  
  <p>A) When the Scheduler attempts to assign the work on the given synchronizationContext, it will already be disposed, so nothing will be provided</p>
  
  <p>B) Somewhere down the lines in the method executing, when I return a response to the client, the synchronizationContext is lost, regardless of anything else.</p>
  
  <p>C) Something else entirely?</p>
  
  <p>If it's A), I <strong>should</strong> be able to fix this by simply doing <code>Thread.Sleep()</code> between scheduling the work and returning a response. (Tried that, it didn't work.)</p>
  
  <p>If it's B) I have no idea how I can resolve this. Help will be appreciated.</p>