Gadget updates not shown while running subroutines

Just starting out? Need help? Post your questions and find answers here.
PitH
User
User
Posts: 16
Joined: Sun Jan 16, 2022 6:12 am

Gadget updates not shown while running subroutines

Post by PitH »

Hello,
i'm not new to Purebasic but new to programming with Window and gadget (OS = win10)

Actually i believe that i'm stupid cause i found not solution within the reference and not on internet.
My Problem:
I created a main window , added a addwindowtimer, two progressbargadgets, a button gadget and a listicongadget
i created loop with windoweven() and on button pressed i set fields text and color of the list icon gadget
and the gosub to a longer subroutine which runs several seconds .
the subroutine sets textfields on listicongadget depending on processing and sets the progressbars.

well now here is the problem, the progressbars work BUT the listicongadget doesn't update
it only updates with the latest text i set after returning from subroutine.

Anyone an idea to solve that problem ?
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Gadget updates not shown while running subroutines

Post by skywalk »

Yes, you have to master the event loop and threads. Search postevent and threads, signalsemaphore from mk-soft or infratec.
Timers are a bandaid and inflexible if you plan more complex threads.
Of course, show your code for better help.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
PitH
User
User
Posts: 16
Joined: Sun Jan 16, 2022 6:12 am

Re: Gadget updates not shown while running subroutines

Post by PitH »

@skywalk

Thanks for your reply

meanwhile i found a useable solution with UpdateWindow_(WindowID(0)) unfortunately it is not in the reference .

now only one problem is left but i wonder why no one had it:
if the program runs and i open another program which covers it on the desktop the programm window freezes while the program still runs.
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Gadget updates not shown while running subroutines

Post by jacdelad »

UpdateWindow_() is a Windows API call, that's why it's not in the reference. You can find the information about Windows API directly from Microsoft.

You didn't listen to skywalk: don't interrupt your event loop.
The program is not freezes (which means the windows is not updated) because of the very thing that skywalk already told you: you do a lot of stuff between calling WaitWindowEvent() again, so no messages are processed, ergo the window doesn't update. If you do something which takes longer, put it into a thread, so WaitWindowEvent () can be processed meanwhile (also this obsoletes your UpdateWindow_()).
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
PitH
User
User
Posts: 16
Joined: Sun Jan 16, 2022 6:12 am

Re: Gadget updates not shown while running subroutines

Post by PitH »

Sorry , as i wrote, sometimes i seemed to be a bit stupid or silly.

in the meantime i checked about threads and changed my program to make use of.

thank you both for your advices.

it works great and now i understand the window behavior.


have a nice day.
Post Reply