First of all, I am very sorry for my English skills.
I am currently developing a web project through dotnet core 3.1 blazor.
As in the source below, I use IJSRuntime to call a Javascript function that takes a long time.
[Inject]
IJSRuntime JSRuntime { get; set; }
private async Task BtnDisplay()
await JSRuntime.InvokeVoidAsync("RefreshWebJS", Data);
}
Javascript function takes a long time, so I added the source below to add a spinner.
private async Task BtnDisplay()
{
showLoadingImg = true; // add
await JSRuntime.InvokeVoidAsync("RefreshWebJS", Data);
showLoadingImg = false;
}
A spinner is defined on the razor page as follows:
@if (showLoadingImg == true)
{
<div style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; text-align: center;">
<img src="/images/LoadingImg.gif" style="position: absolute; top: 50%; left: 50%;" />
</div>
}
"StateHasChanged()" or "await InvokeAsync(() => StateHasChanged())" also doesn't work.
It works fine when I use Task instead of JSRuntime.
await Task.Delay(1000);
Why doesn't it work when I use JSRuntime.InvokeVoidAsync?
Thank you and sorry for reading difficult English .