async await ConfigureAwait
When do you use ConfigureAwait(false) in C# libraries vs ASP.NET Core apps?
Answers use simple, clear English.
Audio N/AQuick interview answer
In library code, ConfigureAwait(false) avoids capturing SynchronizationContext (important for UI/legacy ASP.NET to prevent deadlocks). In ASP.NET Core there is no sync context by default, so it’s less critical but still reduces overhead slightly. Prefer async all the way; never block with .Result/.Wait on UI or request threads.
Detailed answer
In library code, ConfigureAwait(false) avoids capturing SynchronizationContext (important for UI/legacy ASP.NET to prevent deadlocks). In ASP.NET Core there is no sync context by default, so it’s less critical but still reduces overhead slightly. Prefer async all the way; never block with .Result/.Wait on UI or request threads.
Real example & use case
NuGet HTTP helper awaits with ConfigureAwait(false); app controllers await normally.
Pros & cons
Pros: avoids deadlocks in libraries. Cons: after false, can’t touch UI thread without marshalling.