Process continues to run after exiting program

I wrote a program that does everything it’s supposed to do, but it won’t stop. The user thinks its stopped, but the Windows Task Manager shows the process is still running and using almost as much memory as when it was being used. It is not however using any CTU time. The program is used to program and calibrate meters. A thread is used to upload a hex file to the meter’s processor then another thread does the calibration using a serial port and declares to access equipment on a GPIB bus. If I stop the program after the file upload, the process is killed. But if it is stopped after the calibration thread has run, the process continues. I have experimented with Self.Kill statements at the end of the thread and CalThread.Kill statements in the timer that updates the screen and sends the program to its next task after the calibration is done, I have also tried setting the instance of the thread to nil with no effect. I suspect that the thread is being orphaned somehow and not allowing the process to terminate properly. I am hoping someone has found a solution to processes that don’t end.

This condition has existed since 2009 and I can continue to live with it. I became interested in it while updating the program to Xojo (a bigger task than I expected) while adding a new product.

Make sure that all your windows actually close…
I ran into a similar situation where I referred to a window in its own close event causing the window to “open”, but because the main thread had ended, the app hung around.

app.autoquit = true

so runtime quits app if no windows are open.

Autoquit = true in the does not make any difference. If I quit the app before running the calibration thread, there is no orphaned process. Once the calibration thread has run, there is. While there are other windows, it happens even if only the main window has been opened.

In your app.close event put a simple check in if there are windows still open (this includes windows that are hidden)…

MsgBox str(WindowCount())

Where in your code are you calling Quit?

To be clear, if you stop the application while the calibration thread is active that is when the process keeps going (even thought the windows close)? Do you know what/how the declares are accessing the hardware to communicate through GPIB?

Does the thread call out to a shell or external DLL? Those can make your app hang around if the thread doesn’t finish. What if you call Thread.Kill in your Quit routine?

After many hours during the last week, the problem is finally solved. I spent days going through the code shutting down the GPIB connections because I was sure that was the problem after making sure all the windows were closed. The problem turned out to be a window that was never shown, but was hidden. In the Action for the button that started the calibration process, I looked at a checkbox and opened a debug window if checked or hid it. Changing DebugWindow.Hide to DebugWindow.Close solved the problem. I wish I had followed through on Shao’s suggestion but did not think I had any hidden windows.