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?
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.
If this fixed your issue then please 'Mark as Answer'
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.
None
0 Points
1 Post
Regularly Update Client Side UI on Progress of Server Side Task
Sep 24, 2020 10:08 AM|dfenton|LINK
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.
Participant
883 Points
294 Posts
Re: Regularly Update Client Side UI on Progress of Server Side Task
Sep 25, 2020 10:12 AM|ammd|LINK
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.
All-Star
58444 Points
15771 Posts
Re: Regularly Update Client Side UI on Progress of Server Side Task
Sep 25, 2020 02:36 PM|bruce (sqlwork.com)|LINK
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.