Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application process will not close

Tags:

c#

process

wpf

exe

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?

like image 419
Ebikeneser Avatar asked Jun 20 '12 09:06

Ebikeneser


People also ask

How do I force a program to close stuck?

Use Ctrl+Shift+Esc and then Alt+O.


1 Answers

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).

like image 117
Roman Starkov Avatar answered Sep 21 '22 17:09

Roman Starkov