Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does .exe refuse to stop?

I've "inherited" a legacy C#/C++ program that I have to debug. The current problem is that the .exe won't stop after I close the program, i.e. it still shows up in Task Manager.

This is a problem, because it won't let me restart the program, because only one instance can run. Often killing the process doesn't work; I'm forced to reboot.

I was under the impression that when the main program stopped, all the child threads were also supposed to stop, but I may be wrong.

Q: What would cause a .exe to not stop?

like image 646
user20493 Avatar asked Jan 12 '09 22:01

user20493


2 Answers

Child threads will not stop automatically unless they have been specifically set as background threads (i.e., with thread.IsBackground = true).

Edit: It is also possible that the main thread isn't terminating when the form is closed (i.e., there's other code that is set to run after close that isn't completing).

like image 148
Eric Rosenberger Avatar answered Sep 22 '22 01:09

Eric Rosenberger


I find it useful to attach to the running process with the debugger and press the pause button. After that I would inspect the Threads window and see what the stack trace is doing for each of the executing threads. The threads window is hidden by default. Here is more information about how to show it and use it:

http://msdn.microsoft.com/en-us/library/w15yf86f.aspx

like image 24
Steven Behnke Avatar answered Sep 24 '22 01:09

Steven Behnke