Desktop App Not Closing

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 ?

Win10, Xojo 2022r4.1

Thanks,
Steve

You can try to change
https://documentation.xojo.com/api/user_interface/desktop/desktopapplication.html#desktopapplication-allowautoquit

App.AllowautoQuit = true

1 Like

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 :frowning:

Steve

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,.

Thanks @John_McKernon i’ll look into it but never needed to do this on previous desktop projects. Will report back.

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.

Sounded like a great idea @Tim_Hare . Did that but the property is not shown at all so it is not one of my 4 windows.

Below is the window in question:

Confirming:

a. Controls are empty
b. As I said, width and height are 0
c. Type simply states ‘Document = 0’

Like I said, not every time. So far about 1 in 3 to 1 in 5 times it happens.

Bit stumped atm tbh.

Steve

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.

Steve

No, one by one with separate statements. Easy as only 4 actual desktopwindows. Whatever the lingerer was, it wasnt one of mine that I could identify…

I would look for two situations:

  • 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.
4 Likes

after using app.AllowAutoQuit=true in app Open event, put this into Close event of a window:

For i As Integer = WindowCount - 1 DownTo 0
  Var w As Window = Window(i)
  If w <> Nil then w.close
Next

2 Likes

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!

1 Like

Just for the record, and not related to Xojo (I think), I have an application (Amule) who do not want to quit (Cmd-Q) sometimes.

In that case, I force quit it.

I do not know if there is a pattern to get this bad behavior (and I do not use that application every day; only from time to time).