断点时执行代码? [英] Execute code when breakpoint is hit?

查看:25
本文介绍了断点时执行代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在立即窗口中,我可以执行一行代码.我还可以在特定点设置断点,这样当断点被击中时,程序就会停止,我可以在立即窗口中运行我的代码行.有没有办法(包括扩展)自动执行此操作?

In the Immediate window, I can execute a line of code. I can also set a breakpoint at a particular point so that when the breakpoint is hit, the program stops and I can run my line of code in the Immediate window. Is there any way (extensions included) to do this automatically?

推荐答案

或多或少.您可以右键单击任何断点并选择操作..."(VS 2017,请继续阅读旧版本)

More or less. You can rightclick any breakpoint and select "Actions..." (VS 2017, read on for older versions)

那里的唯一选项是打印一条消息,这通常就足够了,但您可以在其中运行任意代码.例如:{Console.WriteLine("Hello World")}

The only option in there is to print a message, which is usually sufficient, but you can run arbitrary code in there. For example: {Console.WriteLine("Hello World")}

在旧版本的 Visual Studio 中,可以通过右键单击并选择When Hit..."来使用该选项:

In older versions of Visual Studio, the option is available by rightclicking and choosing "When Hit...":

这将输出:

你好世界
表达式已被评估,没有价值

Hello World
Expression has been evaluated and has no value

这意味着您可以调用任意方法.任何其他副作用都会影响到您正在运行的应用程序.我有时会用它来临时修补代码中的问题,而无需重新启动 64 位应用程序.

This means you can call arbitrary methods. Any other side effects will carry to your running application. I sometimes use it to temporarily patch a problem with the code without restarting the 64-bit application.

请记住,与正常程序执行相比,这非常慢.

Keep in mind that this is exceptionally slow compared to normal program execution however.

这篇关于断点时执行代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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