ReBuildAll Blog
Thoughts (mostly) on .NET development

Debugger breakpoints from code   (Tips & Tricks)   
Did you ever have the need to stop the debugger from code? That is, without adding a breakpoint in the Visual Studio IDE?

Many times this seems to be a problem when a third party application loads my .DLL assembly and starts executing it. I want to place a breakpoint, but before the .DLL is loaded into this third party host, the breakpoint would not be active, and after the component is activated, it might be too late to place the breakpoint in the IDE.

Solution? Use the following code:

System.Diagnostics.Debugger.Break ();

And like magic, the debugger will stop here just as if there was a brakepont added.

If you are running this as a Windows application, the application error popup will also appear, allowing you to attach a debugger to the process. You can then just start stepping right from this code line forward.



There are no comments for this blog entry.