Application process will not close

Ebikeneser picture Ebikeneser · Jun 20, 2012 · Viewed 23.8k times · Source

I have a WPF application, after closing the app its process app.exe *32 is still running in the processes list in task manager.

I need this to close as when I make an edit to my code I get the following error -

Unable to copy file "obj\x86\Release\frontEndTest.exe" to "bin\Release\app.exe". The process cannot access the file 'bin\Release\app.exe' because it is being used by another process.

I am aware that this sort of question has been asked before here.

However the solution did not work for me by changing my Assembly.cs to -

[assembly: AssemblyVersion("2.0.0")]
[assembly: AssemblyFileVersion("2.0.0")]

I thought that perhaps if I were to find the Window closed event and puttting something like - Process.GetCurrentProcess().Kill(); in the event so that when a user closed the application from the red 'x' button in the top right of the form this would perhaps kill the process?

Answer

Roman Starkov picture Roman Starkov · Jun 20, 2012

So your process is still alive after you've shut it down. This usually means you have a thread that keeps it alive. Here's how you can track it down.

First, attach to it in the debugger:

                                enter image description here

enter image description here

                                        enter image description here

Now open the threads list:

        enter image description here

Double-click each thread you see here:

enter image description here

And you'll be taken to what the thread is currently doing:

                                enter image description here

That, right there, is what preventing the app from shutting down. One would have to exit that loop for the app to exit (or, alternatively, set Thread.IsBackground to true).