2

Say I'm debugging an application. It's paused in the debugger. I hit the Run button. The application being debugged gets focused (and Visual Studio loses focus).

Is there a way to prevent this behaviour?

(And, as a bit of an aside: Why does this happen? Is it Visual Studio deliberately giving that window focus? Or is it a side-effect of the way debugging works on Windows? Or something else?)

For context, see this answer. Although I imagine that, if possible, it would be useful to prevent the focus change in other debugging scenarios as well.

Community
  • 1
  • 1
Andrew Russell
  • 26,924
  • 7
  • 58
  • 104

1 Answers1

-1

It because the alternative is so much worse, focusing events are a Big Deal in gui programming. A debugger must have the absolute minimum impact on the program being debugged to avoid artifacts so restoring everything the way it was before resuming execution is important. Including the focus.

It just a quick Alt+Tab to get back to the debugger.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Problem is, VS gives the program being debugged focus even if it did not have focus before. That's as much of an impact as not giving it focus when it had it before. In particular, it's a huge pain if the program gaining focus triggers breakpoints for code you want to debug when called via something other than the focus change. Edit: Luckily, the option to not give VS focus on breakpoints also stops it forcing focus on the debuggee. – Leo Davidson Jan 26 '22 at 20:29