How to display progress in a long-running process in Blazor WASM

Steve Rehling 105 Reputation points
2024-08-28T20:31:19.86+00:00

I have a very long-running process in my Blazor WASM app and would like to display progress while it's running. Is there an elegant way to do that? I've looked in various forums but haven't found anything as yet. Thanks for any suggestions.

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,584 questions
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 65,576 Reputation points
    2024-08-28T22:38:45.3533333+00:00

    there are any number of progress bars, spinner, popup dialog available in html.

    • If the progress display is all javascript/html you can use jsinterop to update.
    • current blazer WASM is single threaded (all threading is cooperative co-routines). if you want to use razor to update, then you will need to allow the UI main loop to run:
    var notDone = true;
    while (notDone)
    {
       notDone = DoSomeWork();// Make the steps as small as possible, Task.Run is of no use
       StateHasChanged();     // force ui update
       await Task.Delay(1);   // give the UI some time to catch up
    }
    

    you can also use Web Workers to get a separate thread to do the long running process, but this would require converting the long running code to javascript.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.