79159710

Date: 2024-11-05 15:25:03
Score: 0.5
Natty:
Report link

I found someone who helped me understand.

This was his explanation: The main thread that updates the UI needs to have some sort of "break" where it is able to update the UI. In my case the first two status updates invoking the Event were able to update the UI because immediately after them was an "await" that, once completed, provided the "break" that the main thread needed to update the UI, but all of my invocations of the event after that didn't have any "break" for the UI thread to update. I guess that when an async Task completes it interjects into the main thread letting it know it's done and that the main thread may need to do something now and that provides the opportunity to process the StateHasChanged() call.

So while I don't know if this is the best solution I was able to get my case working by making my OnStatusUpdated method async and slipping in an await immediately after invoking the event that updates the UI.

protected virtual async Task OnStatusUpdated(string statusText)
{
  StatusUpdated?.Invoke(this, statusText);
  await Task.Delay(1);
}
Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: HairyIce