Best way to enable a progress wheel

Hello all

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?

Thanks,
Tim

Which event are you putting the progress wheel code in? Try mouse down to show wheel and run the code from a method or even mouse up perhaps?

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]Sub Action() Handles Action
Me.Enabled = False

ProgressWheel1.Visible = True
ProgressWheel1.Refresh

DoSomething ProgressWheel1

ProgressWheel1.Visible = False

Me.Enabled = True
End Sub
[/code]

[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=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]Sub Action() Handles Action
Me.Enabled = False

ProgressWheel1.Visible = True
ProgressWheel1.Refresh

DoSomething ProgressWheel1

ProgressWheel1.Visible = False

Me.Enabled = True
End Sub
[/code]

[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 won’t 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 won’t 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, you’re doing it wrong.

True.

Fully agree on the DoEvents.

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.

No, I’m not mixing invalidate and refresh.

Ich meinte ob Du evtl. Self. statt Me.invalidate benutzt hast.

Let’s get back on topic here. We’re talking about enabling/disabling a progresswheel at the beginning/end of a long process on web.

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