Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use DebugBreak() in C#?

What is the syntax and which namespace/class needs to be imported? Give me sample code if possible. It would be of great help.

like image 829
Prache Avatar asked Sep 19 '08 18:09

Prache


People also ask

What does __ DebugBreak do?

The __debugbreak compiler intrinsic, similar to DebugBreak, is a portable Win32 way to cause a breakpoint. When compiling with /clr, a function containing __debugbreak will be compiled to MSIL. asm int 3 causes a function to be compiled to native.

How do you debug a Python application?

If you're only interested in debugging a Python script, the simplest way is to select the down-arrow next to the run button on the editor and select Debug Python File in Terminal.


2 Answers

I also like to check to see if the debugger is attached - if you call Debugger.Break when there is no debugger, it will prompt the user if they want to attach one. Depending on the behavior you want, you may want to call Debugger.Break() only if (or if not) one is already attached

using System.Diagnostics;  //.... in the method:  if( Debugger.IsAttached) //or if(!Debugger.IsAttached) {   Debugger.Break(); } 
like image 62
Philip Rieck Avatar answered Oct 09 '22 06:10

Philip Rieck


Put the following where you need it:

System.Diagnostics.Debugger.Break(); 
like image 33
MagicKat Avatar answered Oct 09 '22 04:10

MagicKat