Here’s a weird one.
I’ve got an application that I’m developing for a client where, given a certain set of actions, the Close Button will not exit the app but will instead close the window and leave the process going. If I quit the application by going to the File > Exit menu item instead of clicking the Close Button the application exits correctly.
I’ve tried trapping the CancelClose and Close event but it seems as though the issue occurs after both of those events occur. At first I thought it might have been a database handle left open but I explicitly closed them and the problem still persists.
This is, unfortunately, made complicated by the fact that I can’t share any source code as it’s proprietary.
Has anyone experienced anything like this before? Is there any way I can use the debugger to determine what handles, if any, have been left open that the application might not be able to close?
In your App.Open event try
App.AutoQuit = true
That will make your app close when the last window is closed.
Edit: Rick beat me to it.
App.AutoQuit was already set to True
So I just tested and it turns out that in this particular case the App never gets to its Close event.
Somehow the process is stuck unloading between closing the last window and closing the actual application. Is there any way I can figure out what it’s trying to do?
Breakpoint and then step through it until you find yourself in a loop.
The question is where? When I get to Window.close() on the last window and click the step button it doesn’t go anywhere.
I’m heading home for the day but I’ll come back to this thread tomorrow and see if I can give any more information.
Any possibility of any events (including timers) doing a Window.Open() ?
Any possibility of any window hidden instead of closed? (Window.show reopens implicit created windows).
My guess is that you have a window still open but hidden.
Something that tricks a lot of people is Windows that are implicitInstance = True (the default). So if Window1 is an implicit instance you can do this: window1.show. That’s great but if you reference ANYTHING on that window (a property, control, whatever) you actually create an instance of the window even if you don’t intend to.
I highly recommend that you put your windows implicit instance = false. This means you will have to do this:
dim w as new Window1
Why is this good? If you reference window1 directly it will throw a compiler error for you. Easy way to find issues with your windows.
[quote=168453:@Dave Greene]Here’s a weird one.
I’ve got an application that I’m developing for a client where, given a certain set of actions, the Close Button will not exit the app but will instead close the window and leave the process going. [/quote]
If you want the app to quit when you close the window, put Quit in the window close event…
This turned out to be the right answer but for the wrong reason. My understanding of Xojo is that if the last window closes the App is given an implicit
Quit message. Somehow that message wasn’t being sent even though I closed the main window when it was the last one which I confirmed by using
If autoquit is true, the app should quit when the last window is closed. I do not know what you could have done in your code that could prevent the app from closing. In 2015R1, only returning True in app cancelClose does that.
At any rate, glad you finally got the program to behave as you wish.