尽管没有断点,为什么 Visual Studio 仍会获得焦点?
我的应用程序中没有断点,但有时 Visual Studio 会无缘无故地获得焦点。 (在调试模式或不在调试模式)(就像有一个断点)
可能是什么原因?
there is no breakpoint in my application but sometimes Visual Studio get the focus when there is no reason. (in debug mode or not in debug mode) (like there was a breakpoint)
What can be the reason?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果调试器没有因为您手动设置断点或因为应用程序引发异常或遇到其他意外错误而中断,则最可能的解释是您的应用程序正在放弃焦点。
例如,在将焦点设置到应用程序中的另一个窗口之前,您先销毁当前具有焦点且位于前台的窗口。然后,由于某些窗口始终必须具有焦点,因此窗口管理器将激活设置为下一个可用窗口,而该窗口恰好是 Visual Studio 拥有的窗口。产生的效果就像按下 Alt+Tab 一样。
Raymond Chen 有一篇关于此的博客文章,正确的顺序用于禁用和启用窗口:
If the debugger isn't breaking because you've manually set a breakpoint or because the application has thrown an exception or encountered some other unexpected error, the most likely explanation is that your application is giving up the focus.
For example, you destroy the window that currently has the focus and is in the foreground before setting that focus to another window in your application. And then, because some window always has to have the focus, the window manager sets activation to the next available window, which just happens to be the one owned by Visual Studio. The resulting effect would be just as if you pressed Alt+Tab.
Raymond Chen has a blog article about this, The correct order for disabling and enabling windows: