Aspnetcore: Guidance on using ConfigureAwait(...) in async life-cycle methods in Razor component

Created on 29 Aug 2019  路  5Comments  路  Source: dotnet/aspnetcore

The Microsoft.CodeAnalysis.FxCopAnalyzers analyzers recommends (considering) calling ConfigureAwait(...) on awaited tasks.

With that in mind, I would like some guidance on what are the recommended thing to do in the async life-cycle methods, in the context of a Razor component that inherits from ComponentBase?

Is the default (e.g. ConfigureAwait(true)) always the right thing, or is there a benefit to explicitly using ConfigureAwait(false) sometimes, e.g. in OnAfterRenderAsync?

Thanks, Egil

area-blazor question

Most helpful comment

Just for UI related scenarios. For non-UI impacting scenarios (query a data store or a service) ConfigureAwait(false) is useful.

All 5 comments

Somewhat relevant to this discussion: ASP.NET Core already takes some of that burden away from the developer in the MVC stack, where it doesn't matter if you use ConfigureAwait in action methods (it'll always behave as false and calling ConfigureAwait explicitly behaves as a no-op).

So the underlying question here is "Does the same apply to Blazor?"

Thanks for contacting us, @egil.
Our guidance is to simply not use ConfigureAwait in Blazor.

Thanks for contacting us, @egil.
Our guidance is to simply not use ConfigureAwait in Blazor.

Thanks @mkArtakMSFT. Does that include all parts of a Blazor app, e.g. also services, or just the ones directly related to components or the render tree?

Just for UI related scenarios. For non-UI impacting scenarios (query a data store or a service) ConfigureAwait(false) is useful.

Ok, thanks!

Was this page helpful?
0 / 5 - 0 ratings