When you are awaita Task, the continuation by default is executed in a single thread. The only time you ever really need this is that you are running in a user interface thread, and the sequel must also be run in the user interface thread.
You can control this using ConfigureAwait, for example:
await SomeMethodAsync().ConfigureAwait(false);
... which may be useful for offloading work from a user interface thread that does not need to be run there. (But see Stephen Cleary's comment below.)
Now consider this bit of code:
try
{
await ThrowingMethodAsync().ConfigureAwait(false);
}
catch (Exception e)
{
// Which thread am I on now?
}
And how about this?
try
{
await NonThrowingMethodAsync().ConfigureAwait(false);
// At this point we *may* be on a different thread
await ThrowingMethodAsync().ConfigureAwait(false);
}
catch (Exception e)
{
// Which thread am I on now?
}
source
share