Program not closing properly

Hello

I followed a weird behaviour on closing a created Desktop App (Win, Mac, Linux, latest Xojo version) that sometimes the program (or a part of it) is still running (visible it Tasklist/Taskmanager) after closing the App. The weird thing about it: It never happens on closing the App over menu > Exit but it sometimes happens on closing the App by the “x” Button of the window itself. So far I experience this problem in Linux and Windows.

I have to mention that I am using some specific operations that may cause this behaviour:

  • SerialConnect
  • Timer
  • Thread
  • Shell

I also tried to close these components which I am able to, so I created a Close Event to make sure the critical ones will be closed:

  • SerialConnect.Disconnect()
  • Timer.Enabled = False

Not sure if this problem is already known by Xojo but my question is: Are there any mechanism to ensure that the whole Application will be closed?

Looks like this is not a common problem

You could build with profiling on, or get your timers and threads to create a log and see what is running after you close.

On Windows, any shell running will not let your app quit, as will a thread stuck in a loop.

So you need to close your shells and finish your threads.

or the app closed only if all windows are closed

For i As Integer = App.WindowCount - 1 DownTo 0 'do something with the open window App.Window(i) Next

[quote=494253:@Farai Aschwanden]I also tried to close these components which I am able to, so I created a Close Event to make sure the critical ones will be closed:

SerialConnect.Disconnect()
Timer.Enabled = False

Not sure if this problem is already known by Xojo but my question is: Are there any mechanism to ensure that the whole Application will be closed?[/quote]
You’ve got the right idea, but unfortunately I don’t think there is any single method for ensuring everything is shutdown or Nil on app quit.

What I’ve been doing during each Window CancelClose Event I add a check like the following, for any Timers :

[code]If Me.mSpecialTimer <> Nil Then
Me.mSpecialTimer.RunMode = Timer.RunModes.Off
RemoveHandler Me.mSpecialTimer.Action, AddressOf Me.SpecialTimer_Action
Me.mSpecialTimer = Nil
End If

Return False // to ensure quit continues to Close event[/code]

Like Timers, or anything that may perform an asynchronous operation (especially those in a separate thread), you need to add logic to ensure they won’t run continuously or cause infinite loops (as @Lee Badham pointed out) because of the absence of other App properties or objects.

I hope that helps.

I always kill timers and threads as the first step in Window.close events.
Threads shouldnt access any GUI element, but timers can, maybe that is significant?