To make sure work is saved before exit (using _Exit),
First I have Global variable Saved = 0 or -1
1. Set when worked is saved to -1 or when work has changed to 0,
2. A sub that saves the work so it can be conveniently called, it can reset saved from 0 to -1 when work is saved.
So when user indicates they want to quit using _Exit, the Saved variable is checked and If Saved = 0 the user is prompted if they want to save then save routine called and then exit is allowed. If saved is already true then no need to delay exit.
If your program has multiple points to exit just call up a CheckedSaved routine that does the above described stuff.
As mnrvovrfc says, no need to check at regular intervals throughout program. Just check the Saved Flag variable when user wants to exit.
BTW I use that very system with my Account Tracker app in all my GUI apps updates.
PS I had to look at that again, I had a MainRouter sub that jobbed out the execution flow to all other subs from the one MainRouter loop. The only way to exit it was by passing through an _Exit check. The CheckSaved Routine was called after the Main loop was exited. So I was checking for exit every loop through the MainRouter not in timed intervals but in every loop through MainRouter (handling all keypresses and mouse clicks, which basically makes your program event driven).
First I have Global variable Saved = 0 or -1
1. Set when worked is saved to -1 or when work has changed to 0,
2. A sub that saves the work so it can be conveniently called, it can reset saved from 0 to -1 when work is saved.
So when user indicates they want to quit using _Exit, the Saved variable is checked and If Saved = 0 the user is prompted if they want to save then save routine called and then exit is allowed. If saved is already true then no need to delay exit.
If your program has multiple points to exit just call up a CheckedSaved routine that does the above described stuff.
As mnrvovrfc says, no need to check at regular intervals throughout program. Just check the Saved Flag variable when user wants to exit.
BTW I use that very system with my Account Tracker app in all my GUI apps updates.
PS I had to look at that again, I had a MainRouter sub that jobbed out the execution flow to all other subs from the one MainRouter loop. The only way to exit it was by passing through an _Exit check. The CheckSaved Routine was called after the Main loop was exited. So I was checking for exit every loop through the MainRouter not in timed intervals but in every loop through MainRouter (handling all keypresses and mouse clicks, which basically makes your program event driven).
b = b + ...