What does ConfigureAwait(false) do?
Quick Answer
By default, after an await, execution resumes on the captured SynchronizationContext (the UI thread, or classic ASP.NET request context). ConfigureAwait(false) tells it not to — resume on any thread-pool thread. Use it in library code to avoid unnecessary context hops and to prevent deadlocks when a caller blocks with .Result.
When you await something, by default it comes back to the same context — the UI thread in a desktop app, the request context in classic ASP.NET. ConfigureAwait(false) says “I don't need to come back to that context, resume anywhere.” The two reasons to use it are performance — you skip a context switch — and avoiding the classic deadlock where someone blocks on .Result and the continuation can't get back onto the blocked thread. It's a library-code thing. ASP.NET Core has no synchronization context so it doesn't matter there, but library authors add it anyway for portability.
- The deadlock: UI/classic-ASP.NET code calls
SomeAsync().Result; the async method tries to resume on the (now blocked) context — deadlock.ConfigureAwait(false)lets it resume elsewhere. - ASP.NET Core has no SynchronizationContext, so
ConfigureAwait(false)has no effect there — but library authors still add it so their code is safe everywhere. - In app code where you need the context back (updating UI, accessing
HttpContextin classic ASP.NET), don't use it.