The Introduction to ASP.NET Core Blazor article by Microsoft (Daniel Roth and Luke Latham) show examples of awaited calls in the Razor Code, e.g.
@code {
private WeatherForecast[] forecasts;
protected override async Task OnInitializedAsync()
{
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
}
}
However, none of the examples suggest whether the razor pages should continue on the captured context, or not, e.g.
.ConfigureAwait(false);
or
.ConfigureAwait(true);
Does Blazor have the concept of the UI Thread being the only thread able to update components? What is considered "best practice" when calling awaited calls in the Page and/or in page components.
Does Blazor have the concept of the UI Thread being the only thread able to update components?
With Server-side Blazor: yes.
With Client-side there only is one thread (JavaScript) so, yes, kind of.
What is considered "best practice" when calling awaited calls in the Page and/or in page components.
To not use any ConfigureAwait().
You are on a sync context that has an implicit default behaviour of ConfigureAwait(true).
ConfigureAwait() will only be useful when your create extra threads (with Task.Run()) but in general you shouldn't want that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With