Page 1 of 1

ProgressBar not updating until end of loop?

Posted: Fri Aug 09, 2024 4:16 pm
by Nudgy
Hi all,

In a simple loop I am going through all the lines of a List and setting a ProgressBar accordingly. However, the progress bar does not actually change to 100% before the loop finishes entirely. I checked the documentation and forum, but didn't manage to find anything clearly relevant. My guess is that the loop is blocking the progress bar from updating (maybe some kind of threading or DoEvents equivalent is needed?).

For this project, I am using Linux - in case that makes a difference.

Any suggestions?

Thanks.

Re: ProgressBar not updating until end of loop?

Posted: Fri Aug 09, 2024 4:21 pm
by jacdelad
Is your event loop working while your progress stuff happens?

Re: ProgressBar not updating until end of loop?

Posted: Fri Aug 09, 2024 4:53 pm
by Axolotl
pretty sure, that jacdelad leads you to solve your problem.

Otherwise: Any code?

Re: ProgressBar not updating until end of loop?

Posted: Fri Aug 09, 2024 4:56 pm
by Nudgy
jacdelad wrote: Fri Aug 09, 2024 4:21 pm Is your event loop working while your progress stuff happens?
I haven't touched the event loop for the purpose of the "List loop".

In simplified psuedo-code I am just doing more or less the following:

Code: Select all

Procedure x()

      SetGadgetAttribute(#ProgressBarID, #PB_ProgressBar_Minimum, 0)
      SetGadgetAttribute(#ProgressBarID, #PB_ProgressBar_Maximum, NumberOfTotalLinesInList)

     ForEach sourceList()

           SetGadgetState(#ProgressBarID, IncrementedNumberForEachLoop)

          ; Do some stuff with the List here (incuding adding lines to a ListIcon)
     Next

EndProcedure

Re: ProgressBar not updating until end of loop?

Posted: Fri Aug 09, 2024 5:07 pm
by jacdelad
When the function is called, the event loop waits until the function is done. No event processing -> no redrawing. Create a thread to process your stuff.

Re: ProgressBar not updating until end of loop?

Posted: Fri Aug 09, 2024 5:19 pm
by Fred
And if you really don't want to a thread, you can put 'while windowevent() : wend' at regular interval to flush the events.

Re: ProgressBar not updating until end of loop?

Posted: Fri Aug 09, 2024 5:38 pm
by jacdelad
...but be aware that this way all events die painfully without being processed!

Re: ProgressBar not updating until end of loop?

Posted: Fri Aug 09, 2024 6:23 pm
by Nudgy
Fred wrote: Fri Aug 09, 2024 5:19 pm And if you really don't want to a thread, you can put 'while windowevent() : wend' at regular interval to flush the events.
Thanks, Fred. This was actually the first thing I tried, with inspiration from the forum. But it returned the error "[ERROR] WindowEvent(): WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback." Unfortunately, I am not smart enough to figure out what that error means :D I guess it might be caused by the use of BindEvents elsewhere in the code somehow. If you have any hints in that regard, it would be much appreciated.

Otherwise, this might be a good opportunity for me to learn about threading ;)

Re: ProgressBar not updating until end of loop?

Posted: Fri Aug 09, 2024 7:34 pm
by jacdelad
It means exactly what it says: You used Bind...() to let the procedure be automatically called. Procedures called by that are not allowed to use WaitWindowEvent(), because this could cause a fatal sprial of events calling the procedure over and over, stacking it into infinty.

Re: ProgressBar not updating until end of loop?

Posted: Sat Aug 10, 2024 6:58 am
by DarkDragon
jacdelad wrote: Fri Aug 09, 2024 5:38 pm ...but be aware that this way all events die painfully without being processed!
And you can slow down the process by sending events by e.g. moving your mouse.