From Xojo Documentation
The Termination Process in GUI Applications
This is the order in which events are called when a GUI application initiates a termination process, i.e. when it quits:
- Application.CancelClose is called first. If, for any reason, you want to stop the termination process or interact with the user (use a modal window in such a case) to confirm, you should do it in this event. If you return True, the termination process will be stopped immediately.
- Window.CancelClose is then called for each Window, one after the other. If any Window.CancelClose returns True, the termination process will be stopped.
- Windows are all closed, one after the other. In the process, each Window.Close event is called but you can no longer interrupt the termination process.
- If you use asynchronous object like Threads, Timers or sockets, they are terminated by the runtime environment then destroyed even if the runtime did not or could not stop them. If such objects are subclasses and have a Destructor event, it will be called.
- The Application.Close event is called.