In which case does TaskCompletionSource.SetResult() run the continuation synchronously? : <p>Initially I thought that all continuations are executed on the threadpool (given a default synchronization context). This however doesn't seem to be the case when I use a <code>TaskCompletionSource</code>.</p>

<p>My code looks something like this:</p>

<pre><code>Task&lt;int&gt; Foo() {
  _tcs = new TaskCompletionSource&lt;int&gt;();
  return _tcs.Task;
}

async void Bar() {
  Console.WriteLine(Thread.Current.ManagedThreadId);
  Console.WriteLine($"{Thread.Current.ManagedThreadId} - {await Foo()}");
}
</code></pre>

<p><code>Bar</code> gets called on a specific thread and the <code>TaskCompletionSource</code> stays unset for some time, meaning the returned tasks <code>IsComplete = false</code>. Then after some time, the same thread would proceed to call <code>_tcs.SetResult(x)</code>, which by my understanding should run the continuation on the threadpool.</p>

<p>But what I observed in my application is that the thread running the continuation is in fact still the same thread, as if the continuation was invoked synchronously right as <code>SetResult</code> is called.</p>

<p>I even tried setting a breakpoint on the <code>SetResult</code> and stepping over it (and having a breakpoint in the continuation), which in turn actually goes on to call the continuation synchronously.</p>

<p><strong>When exactly does <code>SetResult()</code> immediately call the continuation synchronously?</strong></p>
