async/await and ConfigureAwait
What common mistakes do candidates make around async/await and ConfigureAwait, and how do you avoid them?
Answers use simple, clear English.
Audio N/AQuick interview answer
Common mistakes: Blocking on .Result in ASP.NET legacy context; unnecessary async when no await. Best practices: End async method names with Async; avoid async void except UI events.
Detailed answer
Common mistakes: Blocking on .Result in ASP.NET legacy context; unnecessary async when no await. Best practices: End async method names with Async; avoid async void except UI events. Core: async method returns Task/Task<T>; await yields thread without blocking. ConfigureAwait(false) in library code avoids capturing sync context (UI deadlock prevention). Real-time example: ASP.NET controller awaits DB call — thread returns to pool during IO, scales under load. Pros: Readable async code; integrates with IAsyncEnumerable for streaming. Cons: async void only for event handlers; sync-over-async (.Result) causes deadlocks on UI/legacy ASP. Common mistakes: Blocking on .Result in ASP.NET legacy context; unnecessary async when no await. Best practices: End async method names with Async; avoid async void except UI events. Audience level: Senior.
Full explanation
async method returns Task/Task<T>; await yields thread without blocking. ConfigureAwait(false) in library code avoids capturing sync context (UI deadlock prevention).
Real example & use case
ASP.NET controller awaits DB call — thread returns to pool during IO, scales under load.
Pros & cons
Pros: Readable async code; integrates with IAsyncEnumerable for streaming. Cons: async void only for event handlers; sync-over-async (.Result) causes deadlocks on UI/legacy ASP.
Common mistakes
Blocking on .Result in ASP.NET legacy context; unnecessary async when no await.
Best practices
End async method names with Async; avoid async void except UI events.
Follow-up questions
- How would you test async/await and ConfigureAwait?
- What metrics prove async/await and ConfigureAwait is healthy in prod?
- How does async/await and ConfigureAwait change at 10× traffic?