17

Would there be an option or registry setting to stop Visual Studio auto focusing itself when it hit a breakpoint?

The reason why I don't want Visual Studio auto focus itself is because I tend to do multi-tasking when I debug a software. When I start the debugger, it may takes awhile for the app to compile and hits the breakpoint. I usually takes this waiting time to reply emails.

As I type my email, the debugger would make visual Studio focus on the breaking line, and I would accidentally modified the source code as I am typing my email.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
dsum
  • 1,433
  • 1
  • 14
  • 29
  • 2
    Have you tried typing Ctrl+Z? Turning off Edit+Continue would be another option. – Hans Passant Jan 25 '11 at 00:10
  • I always need to do ctrl + z to undo my accidental changes. I tried turn off Edit+Continue. No luck there. I guess this is a by designed feature with no option to turn it off. – dsum Jan 25 '11 at 16:37
  • [Update] Hans, thanks for the suggestion . After restarting Visual Studio with the Edit+Continue option turn off, it actually helps. Obviously the only draw back is no editing function. – dsum Jan 25 '11 at 18:04
  • Does this answer your question? [Visual Studio: How to stop breakpoint hit from stealing focus?](https://stackoverflow.com/questions/3235373/visual-studio-how-to-stop-breakpoint-hit-from-stealing-focus) – phifi Dec 05 '19 at 15:08

2 Answers2

9

You can easily disable/enable this behaviour with the Option Settings in Visual Studio 2019:

Tools -> Options -> Debugging -> General -> Bring Visual Studio to the foreground when breaking in the debugger

enter image description here

I have no idea with what Visual Studio Version this feature has been added though.

phifi
  • 2,783
  • 1
  • 21
  • 39
  • 2
    I know this is for Visual Studio, but in case anyone coming here is on Visual Studio Code, the corresponding setting there is `debug.focusWindowOnBreak`. – Jeff Mercado Mar 31 '21 at 19:23
  • If my window just flashes when this setting is enabled, are there wider Operating System configurations which can help me overcome that? – MrMesees Sep 10 '22 at 23:41
5

I wasn't able to find any sort of config setting to turn it off but was able to find someone with a workaround; tracepoint.

1. Set your breakpoint at the desired location.
2. Right-click on the red breakpoint dot icon and select “When Hit…”
3. Select “Print a message”.
4. Uncheck “Continue execution”.
You have effectively created a breakpoint that prints out the current function name and thread ID and name and then stops.  Tracepoints don’t steal focus like normal breakpoints do.

Credit goes to: http://dpotter.net/technical/2009/09/problem-solved-visual-studio-stealing-focus-when-breakpoint-is-hit/

JoshKraker
  • 373
  • 1
  • 5
  • 15
  • Thanks for the idea, I learn something new everyday. The tracepoint does print out debug message to the output, however it doesn't stop the debugger from running at the tracepoint. – dsum Jan 25 '11 at 00:23