async-awaitdevexpressblazor-server-side

await Task.Delay(1) in OnInitializedAsync() never returning


This is in code that has been running fine for months. No changes. And all pages except 1 come up fine. But this one page, which has:

protected override async Task OnInitializedAsync()
{
    await base.OnInitializedAsync();

    // commented out to remove that as a cause
    // IsLoading = true;
    await Task.Delay(1);

    // ...

The purpose of the IsLoading is it makes a loading... spinner visible. I have the exact same set of code for most of my pages - works on the rest.

The Task.Delay(1) never returns. If I comment it out, then the first await calling the DB (via EF) doesn't return.

If I don't call await base.OnInitializedAsync(), then the Task.Delay(1) returns instantly. This is ComponentBase.OnInitializedAsync().

What can cause this? I don't see how there can be deadlock as this is the first await inside OnInitializedAsync and so there's nothing that can also be waiting.

Update:

The spinner is in this page's razor as:

<ExLoading Visible="@IsLoading" />

And that component is:

<DxLoadingPanel Visible="@Visible"
                PositionTarget="body"
                IsContentBlocked="true"
                ApplyBackgroundShading="true" />

The <DxLoadingPanel> is a DevExpress component.


Solution

  • h/t to @MayurEkbote as they sent me down the road of removing components from the page to find if it was one of them. It was.

    I had:

    <DxComboBox Data="@EditModel.AllowedWorkplaces"
                ReadOnly="@(ModeState == Mode.Read)"
                InputId="workplace"
                TextFieldName="@nameof(EventPageModelBase.WorkplaceItem.Text)"
                name="@nameof(EventPageEditModel.Workplace)"
                autocomplete="off"
                SelectedItemChanged="@((EventPageModelBase.WorkplaceItem workplace) => OnWorkplaceClick(workplace))"
                @bind-Value="@EditModel.Workplace">Workplace</DxComboBox>
    

    and the problem was that EditModel.AllowedWorkplaces was an array of enum values and EditModel.Workplace was the selected enum. I changed it to create a class that wraps the enum and have the combobox use that class. And it now works.

    The error only occurs if SelectedItemChanged is specified. If that is not specified it works fine with an enum.

    I have no idea why. Reading the documentation for DxComboBox it never mentions a collection of enums. So this may no longer be supported.

    ps - The TextFieldName attribute was added with the change. Originally it did not have that attribute. But that is the only change in the razor code.