DebugBreak() equivalent in C#

前端 未结 4 1134
情书的邮戳
情书的邮戳 2020-12-16 10:42

In C# is there any statement equivalent to DebugBreak()? I want to invoke the debugger when ever a particular condition is met.

4条回答
  •  暖寄归人
    2020-12-16 11:21

    You can use the Break method of the Debugger class, in the System.Diagnostics namespace:

    Debugger.Break();
    

    Now, there's also a different way you can add conditional breakpoints, without mucking about with adding code to your project.

    This of course only works when already running your program through the debugger

    What you can do is first add a regular breakpoint at the location where you want your debugger to stop, then right-click the red dot for the breakpoint:

    breakpoint right-click menu

    and then edit the condition to fit your needs:

    breakpoint condition dialog

    This will then be symbolized with a small + inside your breakpoint dot:

    conditional breakpoint

提交回复
热议问题