© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
19 replies
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();
    }
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()
StateHasChanged()
is invoked before the database is updated with
await DrawService.ActivateDraw(DrawId)
await DrawService.ActivateDraw(DrawId)
. What would be the correct way to refresh the page only after the
await
await
is complete?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ A second operation was started on this context instance before a previous operation completed.
C#CC# / help
2y ago
StateHasChanged not working in timers.
C#CC# / help
2y ago
Blazor StateHasChanged not working properly?
C#CC# / help
2y ago