Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
791 views
in Technique[技术] by (71.8m points)

visual studio - VS2010 (Express) debugger trapping Ctrl+C in Console app

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

  • I do not want to modify the behavior of Ctrl+C.
  • I'm not looking for a work around.
  • I simply want the debugger to NOT break when Ctrl+C is pressed during a debugging session.

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.

  1. Is there a setting to turn this on/off in any version/edition?
  2. Does this setting exist in VS2008, VS2010, or both?
  3. Is the setting exposed in the Express editions?
  4. Is my instance of VS2008 Pro unique? Is the setting something that was exposed in an old version of Visual Studio that has carried over (I have carried over VS settings through many new versions).
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...