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.
ProgressBar not updating until end of loop?
Re: ProgressBar not updating until end of loop?
Is your event loop working while your progress stuff happens?
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Re: ProgressBar not updating until end of loop?
pretty sure, that jacdelad leads you to solve your problem.
Otherwise: Any code?
Otherwise: Any code?
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Re: ProgressBar not updating until end of loop?
I haven't touched the event loop for the purpose of the "List loop".jacdelad wrote: Fri Aug 09, 2024 4:21 pm Is your event loop working while your progress stuff happens?
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?
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.
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Re: ProgressBar not updating until end of loop?
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?
...but be aware that this way all events die painfully without being processed!
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Re: ProgressBar not updating until end of loop?
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 meansFred 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.

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

Re: ProgressBar not updating until end of loop?
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.
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
-
- Addict
- Posts: 2344
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: ProgressBar not updating until end of loop?
And you can slow down the process by sending events by e.g. moving your mouse.jacdelad wrote: Fri Aug 09, 2024 5:38 pm ...but be aware that this way all events die painfully without being processed!
bye,
Daniel
Daniel