Posts

Showing posts with the label Task Parallel Library

ConfigureAwait Pushes The Continuation To A Pool Thread

Answer : Why ConfigureAwait pro-actively pushes the await continuation to a pool thread here? It doesn't "push it to a thread pool thread" as much as say "don't force myself to come back to the previous SynchronizationContext ". If you don't capture the existing context, then the continuation which handles the code after that await will just run on a thread pool thread instead, since there is no context to marshal back into. Now, this is subtly different than "push to a thread pool", since there isn't a guarantee that it will run on a thread pool when you do ConfigureAwait(false) . If you call: await FooAsync().ConfigureAwait(false); It is possible that FooAsync() will execute synchronously, in which case, you will never leave the current context. In that case, ConfigureAwait(false) has no real effect, since the state machine created by the await feature will short circuit and just run directly. If you want to see this in actio...