David Menard
David Menard

Reputation: 2321

Visual Studio - Killing Specific Processes on Stop Debug (Shift+F5)

I have a project that start up a few Processes when launched. The processes are stopped and destroyed in the appropriate destructors (or on the click of a button), and everything is fine. My problem arises when I debug. Of course, when debugging, I won't always close my application "properly"; Most of the time, I will click the "Stop Debugging" button in Visual Studio (Shift+F5) or the thing will just crash. I these cases, I have to go and manually close the processes :(

Just wondering if there is an option in VS2010 Pro. that will allow me to kill the created processes when I stop debugging. I'm thinking of writing a Macro for this might work, but does VS2010 have a built-in feature for this? Kind of like the Custom Build steps, but for debugging!

Upvotes: 6

Views: 2398

Answers (1)

David Menard
David Menard

Reputation: 2321

I will take it from the silence that there is no such feature. So here is the macro for it:

Sub StopDebugAndKillProcesses()
    Dim dbg As EnvDTE80.Debugger2 = DTE.Debugger
    dbg.Stop()
    Dim shell_string As String
    shell_string = "taskkill /F /IM TheProcessToKill.exe"
    Shell(shell_string)
End Sub

Assign it to a button, put it next to the original "Stop" button and your done.

Upvotes: 4

Related Questions