Is there a way to force async/await to continue on the first available thread?
async-await, c#, c#-5.0, multithreading
Solution
If you don't care where the rest of the method continues, use `Task.ConfigureAwait`:
await foo.DoSomethingAsync().ConfigureAwait(continueOnCapturedContext: false);
(You don't have to use a named argument here, but it increases clarity.)
See the "Configure Context" part of Stephen Cleary's "best practices" article for more detail.
Problem
One of the cool things about C# 5.0 is the `async/await` keywords and how it simplifies the plumbing you used to have to write with Task Parallel Library (TPL). My question is if you have thread-agnostic code and you happen to trigger an async operation on the main thread (read: UI thread), but you do not necessarily care if the continuation happens on the main thread, then can you tell the `async/await` paradigm that you want it to be continued on the first available thread, even if it is not the main thread? I would think that being able to do this would greatly increase the efficiency of certain scenarios, but not a silver bullet.