Having trouble with a desktop app. Closing on Windows via the ‘X’ closes the main window (or at least appears to) fine - have confirmed code in the Closing event gets called and executed successfully but the application just hangs after that code has completed (but not all the time)****. The app is very simple - main window and 3 other windows. I have ensured that the other windows get closed explicitly in the Closing event of the main window but still no dice.
Hitting ‘Pause’ after code in the Closing event has been executed shows that there appears to still be a window open but I really cannot track down what it is:
Drilling down into the DesktopWindow doesn’t help much, there is no identifying characteristics of it (e.g. no title and such). It’s Height and Width are both 0.
Feel sure it’s something simple that I’ve overlooked but any ideas ?
Thanks @DerkJ I did try that as well but as from the docs, True is the default value in any case so that didn’t help.
The fact that it is intermittent is of-course a big issue so I have been running user action scenarios through the app to see if I can reliably reproduce it but no joy as yet
Closing a window doesn’t usually make an app quit. I assume there’s a place in your code where the user can tell the app to quit, put Quit in that code, that tells the app to quit. Look up Quit in the Xojo documentation for more info,.
Add a property to each window and in the Open event of each, assign a unique value to the property. Either the window type name or an integer, anything that will help you identify what kind of window is being left behind.
I have no answer for why it appears, but as a sticky plaster:
maybe you could run a bit of code in the close event to detect a window which is ‘not one of yours’, and then close it/ set it to nil?
something like
for each w as desktopwindow in windows
if w isa MyKindofWindow then
//shouldnt be any of mine open by now???
else
//burn the witch
try
w.close
w = nil
catch
end try
end if
next
Thanks all. I am using the Quit method in the main window closing right now and so far so good. Closing of the app seems to mostly take a lot of time but that may be unrelated and I believe more related to the browser based controls that I’m using and their closure…
Up to about 30 or so starts and quits via main window ‘X’ and seems to be working. Thanks @John_McKernon . As I mentioned, I was closing all of my windows (app DesktopWindows) explicitly in this event but occasionally whatever window this is would hang around and prevent the app from closing.
Like I say, so far so good and will do more tests tomorrow. Feels unnatural that my explicitly closing all windows like this doesn’t always close the app but that seems to be the case.
A window which has closed, but not destructed. This can be caused when you have a reference to a Window (or possibly to a control inside the window) that is not nil, when you close the window. This can happen internally (e.g. a property inside the window is pointing to one of the window controls) or externally (e.g. Window2 has a property which points to Window1, or an App property)
A window which was closing, but during or after the close process, re-opened because of ImplicitInstance=true.
As Mike D said, closing the window does not necessarily destruct it and remove it from the list of windows. If you have a reference to the window still lingering, you wind up with a zombie window like you’re describing.
Yeh thanks and understood re lingering references. The issue was that even using the same set of user actions, this behaviour was not reliably reproducible.
That can be infuriating. I always like to say the difference between a surgeon and a programmer is the surgeon does everything he can to keep the patient alive, where the programmer wants to kill the patient over and over until he sees the pattern. Intermittent errors are the worst!