One event loop or multiple?

Mac OSX specific forum
mrbungle
Enthusiast
Enthusiast
Posts: 112
Joined: Wed Dec 30, 2020 3:18 am

One event loop or multiple?

Post by mrbungle »

Is it better to organize all of your events in one big event loop or break them per procedure?

If every event is organized in a single loop, how do you handle logic in other procedures? For example, a settings window?
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: One event loop or multiple?

Post by collectordave »

The answer is 'it depends'.

However PB gives you lots of alternative ways you can have a single loop and you can have multiple event loops but you have to ensure only one is active at any time.

For me with a settings or options window I create the window in a module with all its procedures etc then when the main application calls the settings I disable the main window and start the code in the settings module which creates my settings window. When finished I close the settings and reactivate the main window.

There are times when you may need two or more windows open and active at the same time in this case I choose one windows event loop and you can use the EventWindow() to send the event to the correct window to be processed.

Clear as mud?
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: One event loop or multiple?

Post by mk-soft »

Always use only one event loop and distribute from it. Otherwise you may lose an event that you still need. If a second window is opened, prevent the window from opening again. Either by IsWindow() or the Lock function. DisableMenu(), DisableButton()
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
mrbungle
Enthusiast
Enthusiast
Posts: 112
Joined: Wed Dec 30, 2020 3:18 am

Re: One event loop or multiple?

Post by mrbungle »

Thanks, all. This is helpful.
Post Reply