locked
Regularly Update Client Side UI on Progress of Server Side Task RRS feed

  • Question

  • User-2068774599 posted

    I have a Blazor WebAssembly application. One of the server side methods, which is called after a button is clicked on the UI, creates a number of database records but for various reasons this process can take up to a minute. During this time, the UI isn't providing any feedback to the user until the task is fully completed.

    Is it possible with Blazor WebAssembly for this task to be running whilst the client side sends regular requests to the server to get data on the progress of the task (which I can get via SQL). 

    If this was a console or WinForms application. I'd probably split the main task and the progress updates into two seperate threads but I'm unsure if this is the right way to do it with Blazor WebAssembly. If I can use multithreading here, should it be done on the client or server side? If multithreading isn't possible here, is there an alternative way to achieve this desired functionality in Blazor WebAssembly?

    Any advice would be appreciated. Thanks.

    Thursday, September 24, 2020 10:08 AM

All replies

  • User1358036820 posted

    You could have an indicator on server side that keeps track of whether your task is complete or running (example, simple db table) and then use blazor to periodically poll that table and get status. 

    Friday, September 25, 2020 10:12 AM
  • User-474980206 posted

    You have several options

    the first is to poll just like the windows app. Just use JavaScript interop to create a timer that calls blazor code that makes an async web service call. Note WASM is single treaded.

    the second is to use a signal/r connection. Use signal/r to make the request to hub routine, that updates the database and sends status messages to the client.

    add code to the service worker (written in JavaScript) to do the polling and send a message when completed. Service workers run on separate thread.

    Friday, September 25, 2020 2:36 PM