让调试器在下一个事件上中断 [英] Getting Debugger To Break On Next Event

查看:33
本文介绍了让调试器在下一个事件上中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Visual Basic 6.0 IDE 中,可以中断正在运行的程序,该程序处于空闲状态(等待 UI 线程上的事件)然后按 F8(单步).之后,任何导致代码的单击、鼠标悬停或其他事件都会导致调试器在要执行的下一行代码上中断,这将是事件处理程序中的第一行代码.例如,如果您显示了一个带有 OK 按钮的数据输入表单,您可以在空闲时打破该表单,按 F8,然后单击 OK 按钮.然后,调试器将突出显示 cmdOK_Click 事件处理程序中的第一行代码.

In the Visual Basic 6.0 IDE, it was possible to break a running program that is sitting idle (waiting for an event on the UI thread) then hit F8 (single step). After that, any click, mouse-over, or other event that led to code would cause the debugger to break on the next line of code to execute, which would be the first line of code in the event handler. For example, if you showed a data-entry form with an OK button on it, you could break that form when idle, hit F8, then click the OK button. The debugger then would highlight the first line of code in the cmdOK_Click event handler.

是否可以使用 C# Winforms 项目在 Visual Studio 2017 中执行上述操作?我在 SO 上看到过类似的帖子,这些帖子指示全部中断(Ctrl-Alt-Break),然后按 F11(步入),然后单击表单上的按钮.但这不起作用.当我按 F11 时,程序返回到运行模式并处理事件,而不会导致 IDE 中断并显示事件后要执行的第一行.

Is there a way to do the above in Visual Studio 2017 with a C# Winforms project? I have seen similar posts on SO that instruct to break all (Ctrl-Alt-Break) then hit F11 (step into) then click a button on the form. But that isn't working. When I hit F11, the program goes back into running mode and events are processed without causing the IDE to break and show the first line to execute after the event.

请注意,在 VB6 IDE 中,当您中断程序然后按 F8 任何 之后触发并导致事件处理程序的事件将导致 IDE 中断.我正在为 VS 2017 IDE 和 C# Winforms 程序寻找类似的行为.

Note that in the VB6 IDE when you break a program then hit F8 any event that fires afterwards and leads to an event handler will cause the IDE to break. I am looking for similar behavior for the VS 2017 IDE and a C# Winforms program.

注意:请不要建议进入每个偶数处理程序并在第一行代码上设置断点——考虑到一个复杂的程序可能包含数千个事件处理程序,因此设置断点每个内部都不是一个实用(或优雅)的解决方案.

Note: Please don't suggest to go into every even handler and set a breakpoint on the first line of code--consider that a complex program might contain thousands of event handlers, so setting breakpoints within each is not a practical (or elegant) solution.

推荐答案

F10 (Step Over) 和 F11 (Step Into) 都提供了所需的行为,但如果 Enable Just My代码选项已开启:

Both F10 (Step Over) and F11 (Step Into) provide the desired behavior, but only if Enable Just My Code option is on:

这篇关于让调试器在下一个事件上中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆