I want to enable and show a progress wheel when a button is clicked. However the code to execute showing and enabling only runs after all of the code in button has been completed. So if I tell it to show and enable at the start of the code, then at the end tell it to disable and hide the progress bar at the end of the code, the user sees nothing.
Other than a timer, is there a better way to show that something is happening while the user waits?
that example was for desktop, just saw your target is web.
for the ui updates the event loop must continue but you can force a direct redraw with .refresh
if you stop the event loop (as example with a method that have a long process time) the app freezes.
for longer process you need a thread which runs beside.
if you use doevents the user could press any other menu or button that is enabled, be careful.
[code]Public Sub DoSomething(p As ProgressWheel)
Var a As Integer
Var c As Integer = 0
For i As Integer=1 To 10000000
c=c+1
If (c Mod 1000)=0 Then
App.DoEvents 'or better after each second that the app still responds
End If
[quote=478251:@Markus Rauch]that example was for desktop, just saw your target is web.
for the ui updates the event loop must continue but you can force a direct redraw with .refresh
if you stop the event loop (as example with a method that have a long process time) the app freezes.
for longer process you need a thread which runs beside.
if you use doevents the user could press any other menu or button that is enabled, be careful.
[code]Public Sub DoSomething(p As ProgressWheel)
Var a As Integer
Var c As Integer = 0
For i As Integer=1 To 10000000
c=c+1
If (c Mod 1000)=0 Then
App.DoEvents 'or better after each second that the app still responds
End If
a=a+1
a=a+1
a=a+1
a=a+1
a=a+1
a=a+1
Next
End Sub
[/code][/quote]
And that pattern is still for desktop… that wont work either.
In a web app, nothing is sent to the browser until all of the code that is called from the current event loop finishes. The way to accomplish what you want is to show the progresswheel and then use a web thread or webTimer to do your data processing. When that process completes, hide the progresswheel.
[quote=478271:@Greg O’Lone]And that pattern is still for desktop… that wont work either.
In a web app, nothing is sent to the browser until all of the code that is called from the current event loop finishes. The way to accomplish what you want is to show the progresswheel and then use a web thread or webTimer to do your data processing. When that process completes, hide the progresswheel.[/quote]
Which is the way you should be doing it for desktop too. The rule of thumb is if you need DoEvents or Refresh, youre doing it wrong.
However, it’s been my experience that using refresh in newer versions of macOS is necessary. I’ve had problems with controls or even parts of controls not refreshing correctly. There was even an animation - AnimationKit - where a careful addition of refresh made the animation smooth again.
its better described if a app freeze or hang there is something wrong in the concept. @Beatrix Willius
are you sure u not mistaken self.invalidate and me.invalidate ? i just had this these days.
You cannot change the UI during an event. It will only take place at the end of the event.
The simplest way is to show the indefinite progressbar in the MouseDown event of the button, and then do what you want in the Action event. And when the process is finished, do ProgressBar1.visible = False