Stop debugging on device disconnect

Anyone know if there is a plugin or an option to tell VS to stop debugging when the debug target is disconnected?

Not sure of way to do this from VS (may be some VS event you could hook, not sure).

I have used this method to wait for exit on device. Call this code before main exits.
Hit LDR button to exit app. Hit LDR again to detach debugger. Not sure why second LDR press detaches debugger. Maybe an internal exception is thrown if no listener any longer.

static void WaitTillLDRPressed()
    Debug.Print("Press LDR Button to exit Main.");
    AutoResetEvent wait = new AutoResetEvent(false);
    FEZ_Components.Button ldr = new FEZ_Components.Button(FEZ_Pin.Interrupt.LDR);
    ldr.ButtonPressEvent += (FEZ_Pin.Interrupt pin, FEZ_Components.Button.ButtonState state) =>
    ldr = null;

Problem is, I use the LDR button in my code :wink:

You can use another button. Should probably use external button anyway so as not to where out the ldr button.