I have a desktop application form which i am launching another application and closing current one.
Current application is closing but i can still see its process in task manager due to which i am not able to delete that exe from launched application.
i am using ‘Quit’ to close my application.
Can anyone help me to close application completely ?
It should be noted that Windows doesn’t do any checking to see if the app is already running like macOS does, so if that first app doesn’t quit and is brought to the foreground again, you’ll get another instance of the second app.
I’ve seen this happen when working on Windows builds. Windows users used to report it happening with my apps too, after quit. Since then, in all my apps I’ve use this method, which solves the problem …
Public Sub KillWindowsProcess()
// kill the app, only on Windoze
// this works but may not be 64-bit compatible
' #if TargetWin32 then
' Declare Function GetCurrentProcessId Lib "Kernel32" () As UInt32
' dim PID as UInt32 = GetCurrentProcessId()
' dim s as new shell
' s.Execute("Taskkill /PID " + str(PID) + " /F")
' #endif
// this works for both 32-bit and 64-bit builds
' and will not kill any same-named applications
dim s as new shell
dim p as new WindowsProcessStatisticsMBS
dim pID as integer = p.ProcessID
s.Execute("Taskkill /PID " + str(pID) + " /F")
End Sub
… which gets called as the last command in App.Close
' stop lingering process on Windows
#if TargetWin32 then
App.Log( "Killing Windows process" )
KillWindowsProcess
#endif
This way there is never a lingering process after quitting on Windows.