Application is still running in memory after Application.Exit() is called

Praveen Manupati picture Praveen Manupati · Jul 31, 2014 · Viewed 17.2k times · Source

The application I am building is still running in memory (checked in Task Manager) after it is closed using Application.Exit(). Because of this when I am running it again after closing it as mentioned above, I am getting this error "Only one instance at a time". Can you please tell me how to completely close my application?

Answer

Robert Anderson picture Robert Anderson · Jul 31, 2014

It seems that this is a Windows ap and you are calling System.Windows.Forms.Application.Exit() but there is a thread still running in the background. Have you tried

Application.ExitThread();

Environment.Exit();

You could kill the process as Jonesy mentioned, passing in the process ID of the process if it is a separate application than the current running process.

For that, you need to use the System.Diagnostics.Process namespace and loop through the currently running processes to get the right pid and then call kill on that pid.