2

My c# application executes a second process, when I stop the debugging the second process lives on and I can't rebuild because the .exe of the process is still in use.

Gowtham A
  • 31
  • 2
  • 2
    Possible duplicate: [Killing child processes when debugging ends](http://stackoverflow.com/questions/7955680/killing-child-processes-when-debugging-ends) Strongly related: [Kill child process when parent process is killed](http://stackoverflow.com/questions/3342941/kill-child-process-when-parent-process-is-killed) – Cody Gray - on strike Mar 15 '16 at 10:52
  • If you only need to do this for a particular process while debugging, you can set up your system to [automatically start the process with the debugger attached](https://msdn.microsoft.com/en-us/library/jj919165.aspx#BKMK_Automatically_start_an_process_in_the_debugger). I would flesh this out into an answer, but your question is so devoid of details that it's hard to recommend something useful. – Cody Gray - on strike Mar 15 '16 at 10:55

1 Answers1

0

It can't be done automatically with just Visual Studio.

One option would be to create a pre-build step, which you can define in your C# project file. In that pre-build step you execute a separate program where you find the process and kill it. That program could be just another C# program.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
  • It's easy to stop a program that is being debugged(Debug -> Start Debugging) in visual studio, but is there a way to stop a program that was started without debugging(Debug -> Start Without Debugging)? – Gowtham A Mar 15 '16 at 10:54
  • The problem you describe happens on compiling. This answer fixes that. How it was started doesn't matter. – Patrick Hofman Mar 15 '16 at 10:56