如何:使用条件创建断点? [C# 快车]

发布于 2024-07-24 14:23:17 字数 229 浏览 8 评论 0原文

我现在一直在我的 Visual C# 2008 RSS Feed 中看到这个:

http://lincolnfair.net/oldLincolnFair/mad.jpg< /a>

我很确定这是 VS 2010 独有的功能,但我想知道是否有办法在 VS 2008 中复制此功能?

I've been seeing this in my Visual C# 2008 RSS Feed forever now:

http://lincolnfair.net/oldLincolnFair/mad.jpg

I'm pretty sure this is a VS 2010 only feature, but I was wondering if there is anyway to replicate this in VS 2008?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寂寞美少年 2024-07-31 14:23:17

与 @Relster 类似,我有一个代码片段,其中

#if DEBUG
    if( node.Name == "Book" )
        System.Diagnostics.Debugger.Break();
#endif

node.Name == "Book" 根据我想要测试的条件进行更改。 #if DEBUG 包装器确保检查永远不会释放代码。

这也比在 Visual Studio 中使用条件断点快很多。 当您使用内置条件 bp Visual Studio 时,必须闯入应用程序,暂停所有线程,评估表达式并在每次遇到断点时确定它是否为真。 在紧密循环中,这可能是接近完全执行性能和缓慢运行之间的差异。

Similar to @Relster I have a code snippet with the following

#if DEBUG
    if( node.Name == "Book" )
        System.Diagnostics.Debugger.Break();
#endif

Where node.Name == "Book" changes based on the condition I want to test for. the #if DEBUG wrapper makes sure the checks never make it to release code.

This is also a lot faster than using the conditional breakpoints in Visual Studio. When you use the built in conditional bp visual studio has to break into the app, pause all the threads, evaluate the expression and determine if it is true each time it hits the breakpoint. In a tight loop this can be the difference between near full execution performance and running at a crawl.

草莓酥 2024-07-31 14:23:17

你也可以在 VS 2008 中做到这一点。 我确信有很多方法可以做到这一点,但一种方法是右键单击现有断点和断点边缘的红点。 选择 condition...,然后给它一个计算结果为 bool 的条件,只有在为真时才会中断。 条件语句应该能够访问设置断点的行范围内的任何内容。

该上下文菜单中还有其他选项,允许您过滤会导致中断的内容(例如仅某些线程)、根据命中断点的次数进行中断、命中断点时运行宏等。

You can do it in VS 2008 too. I'm sure there's many ways to do it, but one way is to right click on the red dot in the margin of an existing breakpoint & select condition..., then just give it a condition that evaluates to a bool and it will only break if that's true. The conditional statement should have access to anything that's in scope at the line where the breakpoint is set.

There's also other options in that context menu that allow you to filter what will cause a break (for example only certain threads), break based on the number of times the breakpoint has been hit, run macros when you hit the breakpoint, etc.

Smile简单爱 2024-07-31 14:23:17

另一种方法是创建自己的条件并使用调用:

System.Diagnostics.Debugger.Break(); 

虽然它可能不像 VS2010 设置断点的方法那么复杂,但您可以用最少的代码开销获得相同的效果。 只要记住在构建发布代码时将这些东西取出即可。

注意:在VS2008和VS2005中,您可以通过设置常规断点(F9或在装订线中双击)来设置条件断点,然后右键单击该断点以设置“条件...”。 VS2008 Express Edition 中不提供设置条件断点的功能。

The other way to do this is make your own conditions and use a call to:

System.Diagnostics.Debugger.Break(); 

While it may not be as sophisticated as the VS2010 way of setting breakpoints, you can get the same effect with minimal code overhead. Just remember to take that stuff out when you build release code.

Note: In VS2008 and VS2005, you can set a conditional breakpoint by setting a regular breakpoint (F9 or double click in gutter), and then right clicking on that breakpoint to set the "condition...". The ability to set conditional breakpoints is NOT available in the VS2008 Express Edition.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文