Background process after quitting app (Windows 10)

I saw that another person had a similar problem but could not solve the problem.

Basically, after closing my application with the X button, it is still open as a background process.
Unfortunately, it doesn’t even fire the app closing event.

My application uses shells, one timer, two sockets, an image viewer and a MySQL database.

The shells run in asynchronous mode, and they have to run in asynchronous mode. There’s no way around that. How do I close the Shells? I guess I can’t close the Shell in the completed event, can I? Then the completed event would be fired again.

The execute method of the shell is executed in the pressed event of a button. As I said, I use asynchronous mode, which means that I can’t use the close method directly after the execution of the shell. It would interrupt the execution of my shell command.

And, as I mentioned before, the closing event is not fired, so I can’t close the shell there either.

Do you have any ideas on how to solve this problem?

i would try .Close
or have you tried what happens if your shell object get nil?
are all windows closed?
could u use a System.EnvironmentVariable and read it in your asynchronous running shell to interrupt?

This should do it:
Funtion provided by @Andrew_Lambert on this forum here:

Function KillShell(sh As Shell) As Integer
#if TargetWindows Then
  Declare Function TerminateProcess Lib "Kernel32" (ProcessHandle As Integer, ExitCode As Integer) As Boolean
  Declare Function GetLastError Lib "Kernel32" () As Integer
  If TerminateProcess(sh.PID, 0) Then
    Return GetLastError()
  End If
#else
  sh.close
#endIf
End Function

Modified to be cross platform

Unfortunately, it didn’t work. :frowning:

I used the function inside the completed event of the Shell, but it didn’t work. So it didn’t stop the background process of my application in the task manager.

Use it in the destructor of your class. Completed is only fired “IF” the process has exited, but your issue is that it “ISNT” exiting…:wink:

Thank you, I’m going to check it tomorrow because I will go to bed now.

I know what a destructor() is, but I don’t know what you mean by destructor of my “class”. Which class do you mean?

I guess you’re referring to my main Window named Window1 and I would have to create a method called destructor() inside Window1 according to the docs. So I will just put the KillShell() method inside the destructor method of Window1. Is this correct?

Because if I close Window1, it will close the Application.

If you subclass the shell class you can add a method called destructor. But you can also call the shell kill function on window.close or app.close depending on where you store the shell property

In the close event of your application,
Run

Shell.Execute(“taskkill /f /im nameoffShellApp”)

Replacing name of shell app with the executable that’s locking up the shell. The executable will immediately terminate and allow your program to terminate-in-full.

What’s happening is, the executable is still running after detaching from the Shell and keeping your app “alive.”

Alternately, if the executable you’re running has a terminate command, send that to your executable from the Shell (ie CMD.exe or PowerShell could be terminated by sending “exit” command, then closing the app using Quit or the ‘x’)

I solved the issue with your help. Thank you :slightly_smiling_face:

1 Like