C#C
C#2y ago
Maverick

Invoke StateHasChanged() only after asynchronous operation has completed

Referring to the code below:
private async void PublishDrawWithConfirmation()
    {
        var result = await DialogService.ShowMessageBox(
            "Publish Draw",
            "Once published, the draw will no longer be editable and will be open to entries. Are you sure?",
            yesText: "Publish", cancelText: "Cancel");
        
        if (result == null) return;

        await DrawService.ActivateDraw(DrawId);
        Snackbar.Add("Draw has been published!", Severity.Success);
        StateHasChanged();
    }


My intent is to refresh the page after updating the database, in order to display the updated information. Based on the behaviour I am seeing, it looks as if
StateHasChanged()
is invoked before the database is updated with
await DrawService.ActivateDraw(DrawId)
. What would be the correct way to refresh the page only after the
await
is complete?
Was this page helpful?