When do I need to worry about tasks leading to multithreading? : <p>Say I have code like this:</p>

<pre><code>...
var task1 = DoWorkAsync(1);
var task2 = DoWorkAsync(2);
await Task.WhenAll(task1, task2);
...

private async Task DoWorkAsync(int n)
{
    // Async HTTP request that we ConfigureAwait(to be determined).

    // Some CPU-bound work that isn't thread-safe.
}
</code></pre>

<p>So if I'm in a WPF app and I don't <code>ConfigureAwait(false)</code> on the HTTP request, am I safe here? The two HTTP requests can be made concurrently, but the tasks have to resume on the UI thread, so the CPU-bound work isn't multi-threaded? But if I do <code>ConfigureAwait(false)</code>, the tasks can resume their CPU-bound work in parallel on different thread pool threads so I'm in trouble?</p>

<p>If I'm in ASP.NET it can happen either way because the synchronization context doesn't have anything to do with a thread like WPF?</p>

<p>And what if I'm in a console app?</p>

<p>How do I talk about <code>DoWorkAsync</code>? Do I say 'it's not safe to <code>DoWorkAsync</code>s concurrently'?</p>

<p>Is there a normal way to redesign it? The important part to do concurrently is the HTTP request, not the CPU-bound work, so do I use a lock or something (never used before)?</p>
