DialogService.Confirm dialog closes only after long-running operations – UI freeze perception

I’m using the following code block in my application:

string deleteText = string.Format(L["DeleteBuchungConfirm.Text"], balanceType);

if (await DialogService.Confirm(deleteText, L["DeleteConfirm.Header"], new ConfirmOptions()
{
    OkButtonText = L["OkButton.Text"],
    CancelButtonText = L["CancelButton.Text"]
}) == true)
{
    // Löschen wurde bestätigt, Dialog erstmal zumachen, Ladebalken einblenden, Datensatz Buchung löschen

    DialogService.Close();
    progressBarVisible = true;
    await InvokeAsync(StateHasChanged);
    await Task.Delay(100);

    var deleteResult = await webassetsService.DeleteBuchungen(buchung.BuchungId);

    if (deleteResult != null)
    {

        IEnumerable<WebAssets.Models.webassets.Buchungen> buchungen_old = await webassetsService.GetBuchungen(new Radzen.Query
        {
            Filter = "i => i.BuchungAsset == @0 && i.BuchungBilanz == @1",
            FilterParameters = new object[] { asset_changed.AsId, bilanzartAktiv }
        });
        
        foreach (WebAssets.Models.webassets.Buchungen buchung_o in buchungen_old)
        {
            // Lösche Buchung, falls sie:
            // - keine händisch eingegebene Buchung ist
            // - nicht im festgehaltenen Jahr liegt
            // - nicht vor dem Anschaffungsdatum liegt                             
            if (buchung_o.BuchungArt < 3
                && buchung_o.BuchungDatum.Year > einstellungen.PrefAbschluss
                && buchung_o.BuchungDatum > asset_changed.AsAnschaffung)
                await webassetsService.DeleteBuchungen(buchung_o.BuchungId);
        }

        // bis dato eingegebene Buchungen werden gelöscht und neu geschrieben
        await neuberechnungService.Neuberechnung(asset_changed, bilanzartAktiv);

        await grid0.Reload();
        await AddLastCalledAsset(asset_changed.AsId, true);
    }
                      
    await InvokeAsync(StateHasChanged);
    await Task.Delay(100);
    progressBarVisible = false;
}
else
{
    DialogService.Close();
}

When deleteResult is not null and the confirmation dialog is acknowledged by clicking "OK", the dialog only closes after all the calculations and database operations are completed — even though the DialogService.Close() call comes first in the code.

To the user, this creates the impression that clicking "OK" has no effect or that the application has frozen. Ideally, the dialog should close immediately after the confirmation, and then all the background operations (which involve database operations) should begin.

To improve the user experience, there’s even a loading indicator intended to show that a long-running process is underway. However, because the dialog remains open until everything finishes, this progress indicator is either not visible or barely noticeable behind the dialog window.

Is there a recommended way in Radzen to close the dialog immediately and let the expensive operations continue afterwards so that the loading indicator can be displayed properly?

The approach used in this demo might help in your case as well - await Task.Yield();: