Monday, December 21, 2020

Saturday, December 5, 2020

Async Blazor

 While making quick dirty things in Blazor server-side app, don't drown with EventCallback<> for controls and calls of (awaited async) methods in markup like

@foreach (var item in GetItems())

. This causes UI to stop reacting to events and updating . Lamer's attempts of ConfigureAwait() didn't solve problems. Use props bound to markup and OnChanged Action<> as control property. Making event handler async or using GetAwaiter().GetResult() will hang:

<AccountSearch OnAccountSelected="OnAccountSelected" />

    private async void OnAccountSelected(int accountId)

    {

        _accountId = accountId;

        _bans = await DbUtils.LoadAccountBans(_sqlProvider, _accountId, _all);

        StateHasChanged();

    }