I have a Blazor server site with a simple method that is supposed to do the following:
- Start spinner on the button
- Execute the
SaveChanges
, - Stop the spinner and display a message pop up alerting the user of the result,
- Clear the message after 5 seconds.
Here is the code:
private async Task HandleValidSubmit() {
// Start spinner
Icon = "spinner-border spinner-border-sm";
try {
Context.Update(Case);
await Context.SaveChangesAsync();
message = "Key info successfully updated";
messageStatus = "success";
} catch (Exception ex) {
message = ex.Message;
messageStatus = "danger";
}
// Stop spinner
Icon = "k-icon k-i-save";
await Task.Delay(5000);
messageStatus = " d-none";
}
When running the method however, the spinner is shown for five seconds and no message appears. If I comment out the await Context.SaveChangesAsync();
it runs as expected.
Why is the spinner not stopping when the first await
finishes, and why is the message not showing for 5 seconds? Does it have anything to do with having two await
calls?
What am I doing wrong? Any help is appreciated.