Hi I’m building a background task to delete some data. It could easily be a long running process. What I’m trying to achieve is to update a progress bar in the client while the deletes are taking place. I have code like the following.
Public Sub DeleteData() Dim min as Integer = 0 Dim max as Integer = 0 Dim current as Integer = 0 Application.StartTask(Sub() _view.SetStatus("Deleting Buses", min, max, current) Application.Update(_view) DeleteBuses(current) _view.SetStatus("Deleting Cars", min, max, current) Application.Update(_view) DeleteCars(current) End Sub) End Sub
(btw – is there a guide somewhere for how to format code on these forums?)
So the above Application.Start w/ Application.Updates seem to work – sort of.
The task executes in the background without the ajax spinner, so that is good. But the UI only updates if I happen to click somewhere in the page in the browser. When I click it seems to paint the updated progress bar.
_view is a reference to a user control (through an interface) where the progress bar is.
_view.SetStatus method sets the properties on the progress bar, and it also sets progressBar.Update and progresBar.Refresh (only because i was trying to make it work, I don’t think that should be necessary.).
Any advice – or where I’m going wrong?
I believe 100% that it is possible to update a progress bar on the client from a long running server side process. But can’t seem to make it work without clicking on the UI while it is running.
Any assistance would be appreciated…
That was it! Thank you Luca. My dev machine is still Win7 so I don’t think websockets is running by default.
My hosting company has support for Websockets and so I deployed the test project there and it worked perfectly. I ended up coding in a timer which I enable only if websockets are not active as a sort of backup, in case the code runs in an environment where that is the case.
So I’m all set – thanks for the assist Luca and Andrew.
At what point do you check Application.IsWebSocket? If it’s in Program.Main it will always be false since the first load is http. If you check inside the task and it’s still false then it means that it’s not enabled on your server. Wisej always uses WebSocket mode if available on the client browser and the server.
If you are debugging with IIS Express and VS, WebSocket is enabled by default starting from Windows 8 (I think). IIS needs the WebSocket module enabled using the Windows features installer.
So Application.IsWebSocket is returning False.
I do not have the default of true for enableWebSocket overridden in Json.default, so I thought it would be using websocket mode by default. Is there something I need to do to get the app to switch to WebSocket mode?
I can make this work ok w/ the timer, but I’d rather have a more elegant solution.
Thanks in advance for the assistance…
Application.Update() can push the updates only in WebSocket mode. Otherwise you need a timer or another event to trigger a browser request.
We have a demo with code here: https://wisej.com/blog/progress/
Check if you are in WebSocket mode using Application.IsWebSocket. It’s always false when first loading the app in Program.Main since the first load is necessarily http.
The behavior you described is exactly what would happen with WebSocket off.
I had to do something similar and ended up using a timer control on a form with a 10ms interval that would refresh the progress bar each tick. Probably not the cleanest work around but it works.
Please login first to submit.