Skip to content

ConfigureAwait

Question

Describe ConfigureAwait.

Short interview answer

ConfigureAwait(false) tells an awaited task not to require resuming on the captured context. It is commonly useful in context-agnostic library code; UI code that updates UI state may need the context.

Detailed answer

ConfigureAwait configures how an await continuation interacts with the context. It is not a universal performance switch or a substitute for correct async design. Choose it based on whether continuation code requires a specific context and follow the conventions of the application framework and library.

For example, a library method that only parses a response can write var text = await response.Content.ReadAsStringAsync().ConfigureAwait(false);; a UI event handler that updates a control after awaiting must preserve its required UI context instead.

Sources