Summary of Answers
To avoid the debugger trapping Ctrl+C first turn off the Visual Studio Hosting Process (found in project properties, Debug tab)
If you're using the Express version of Visual Studio, that's all you can do.
If you're using the Pro or better version of Visual Studio you can additionally open Debug > Exceptions..., Win32 Exceptions, and uncheck Ctrl+C.
As as alternative, you can use Ctrl+Break when debugging, unless like me Ctrl+C is hard-wired into your brain.
Original
The following has been edited. Hans seems to have retracted his answer, but his questioning has helped me to narrow down the problem statement:
Extra Clarity
Please note that the following example is contrived. It's just to demonstrate the behavior. I changed the ReadKey line as it was distracting people.
Debug (run) the following program:
class Program
{
static void Main()
{
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
}
}
Press Ctrl+C. The debugger will break as if you set a breakpoint on the Sleep line.
How do you turn this off? I don't want the debugger to break at all for Ctrl+C.
This doesn't happen at home with VS2008 Pro.
I have now tried it with both VS2008 Express and VS2010 Express (the only editions I can test it with easily) and they all do it. This has led me to believe that either it's an Express behavior, or that there is a setting somewhere to toggle it on/off.
Press F5 to run the program in Debug mode. Another way to start debugging is by choosing Debug > Start Debugging from the menu. Enter a string in the console window when the program prompts for a name, and then press Enter . Program execution stops when it reaches the breakpoint and before the Console.
To end a debugging session in Microsoft Visual Studio, from the Debug menu, choose Stop Debugging.
To start debugging, select F5, or choose the Debug Target button in the Standard toolbar, or choose the Start Debugging button in the Debug toolbar, or choose Debug > Start Debugging from the menu bar. The app starts and the debugger runs to the line of code where you set the breakpoint.
In the Visual Studio toolbar, make sure the configuration is set to Debug. To start debugging, select the profile name in the toolbar, such as <project profile name>, IIS Express, or <IIS profile name> in the toolbar, select Start Debugging from the Debug menu, or press F5.
Perhaps this is common knowledge by now but we were having the same problem when trying to stop a topshelf application using ctrl-c while being debugged in visual studio. In the end we figured that you need to turn off capturing control-c win32 exceptions when thrown (Debug->Exceptions, or ctrl d,e open Win32 Exceptions then uncheck control-c in the thrown column) and then also go to the project (that is running the service) properties and on the debug tab check the option enable unmanaged code debugging. We are using MS Visual Studio 2010 pro version 10.0.40219.1 SP1Rel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With