Page 1 of 1

One event loop or multiple?

Posted: Thu Sep 30, 2021 1:28 am
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?

Re: One event loop or multiple?

Posted: Thu Sep 30, 2021 4:02 am
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?

Re: One event loop or multiple?

Posted: Thu Sep 30, 2021 10:45 am
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()

Re: One event loop or multiple?

Posted: Thu Sep 30, 2021 1:43 pm
by mrbungle
Thanks, all. This is helpful.