Welcome to MSDN Blogs Sign in | Join | Help

Sara Ford's Weblog

My adventures embracing open source on CodePlex and at Microsoft

News

    • Did you know... All author proceeds go directly to sending Hurricane Katrina survivors to college.

      Microsoft Visual Studio Tips book

      Recent Entries

Did you know… You can break the debugger without using Breakpoints? - #313

If you are using VB, you can add the keyword Stop in your code to suspend execution. The Stop statement is the equivalent to adding a breakpoint. Sometimes it is just faster to type “Stop” than it is to remember to hit F9 or reach for the mouse.

VB Stop example

If you are using C#, you can use the Debugger.Break() method in your code, provided you are using the System.Diagnostics namespace.

C# Debugger.Break() example

Technorati Tags: ,
Posted: Monday, September 15, 2008 3:00 AM by saraford

Comments

Rory Primrose said:

I found Debugger.Break() really helpful when I needed to debug a Windows Service application as it was starting up. Sometimes it was too late to start the service then attach the debugger.

# September 15, 2008 8:01 AM

santiiiii said:

You can also break with "debugger" in javascript.

# September 15, 2008 10:18 AM

GregM said:

In C++, it's _CrtDbgBreak() (_DEBUG only), or DebugBreak(), or _asm { INT 3 } (x86 only).

Rory, see also Image File Execution Options (http://blogs.msdn.com/greggm/archive/2005/02/21/377663.aspx for example) (no, that's not me).

# September 15, 2008 2:12 PM

Morten said:

Easier than pressing F9 ??? Give me a break! This is ugly and messy.

# September 16, 2008 4:09 PM

Horatio Nelson said:

... and then move your code to production and scratch your head while you try to figure out why your web app is crashing....

# September 19, 2008 2:14 PM

DarthObiwan said:

Another great one is Debugger.Attach(). This is useful when you are working on managed code hosted in an unmanaged application. Instead of doing the whole "Attach to Process" it just prompts you to attach itself.

# September 19, 2008 4:06 PM

Richard said:

"Easier than pressing F9?"

Sometimes the code you want to debug is launched by someone else and you can't easily launch it in the debugger yourself.  So you put that in your code and you'll be prompted to JIT debug the code.

# September 29, 2008 1:20 PM

xjb said:

# March 2, 2009 8:18 PM
New Comments to this post are disabled
Page view tracker