Refresh a component visibility

This is most likely a very simple issue.
I have a progressbar that I want to show when a button is clicked (which starts a long running function) and then make invisible when the function completes.

*</div>*
  • *
  • *

protected async System.Threading.Tasks.Task BtnProcessClick(MouseEventArgs args)
** {**
** Globals.lblStatusText = "In Process";**
** Globals.bShowRunning = true;**
** Globals.lblStatusText = "Processing";**
** Globals.ErrorMsg = "";**
** Globals.bFirst = false; **
** Reload(); /* InvokeAsync(StateHasChanged).Wait(); /*
** var selectedXlsxResult = await SelectedXLSX();**
** }**

The progressbar is set to (Globals.BShowRunning = true) when the button is invoked but the progressbar does not become visible until the long running function completes.and other GUI buttons become visible..
I am making numerous calls to InvokeAsync(StateHasChanged).Wait(); without any obvious effect.

Any assistance would be appreciated.

This is a common Blazor issue - it doesn't flush UI updates immediately after calling StateHasChanged - it buffers them instead. As a result the UI will update after your entire method finishes. Users have had success by adding await Task.Delay(1); or await Task.Yield() before the long running operation: TIP: Display IsBusy on long server method

Also you can check our forum FAQ for tips how to format your code.

Thank you Korchev
Did you mean to type await Task.Delay(1) ?
I was able to get things working using Task.Delay(1).
It actually solved multiple areas of frustration with my UI.

Yep. That's exactly what I meant!