How Do I: Create a Breakpoint Using Conditions? [C# Express]

后端 未结 3 1279
孤城傲影
孤城傲影 2021-01-02 22:10

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 featu

3条回答
  •  别那么骄傲
    2021-01-02 22:30

    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.

提交回复
热议问题