views:

477

answers:

4

Is there a way to skip code without having to set a breakpoint after it? I am using the debugging to explore code with a GUI painting event that runs lots of times. I wish to see what comes after the event is done triggering without having to click next a bunch of times.

+32  A: 
[DebuggerHidden]

When this attribute is attached to a constructor/method/property or indexer then that code is hidden from the debugger, it will not be possible for you to step into the code, the debugger will just skip over the code. Even if you set a breakpoint inside one of the pieces of code decorated with this attribute, the debugger will ignore it.

[DebuggerStepThrough]

This attribute is the same as the DebuggerHiddenAttribute, apart from the fact that you can set a breakpoint inside the code which has been decorated with the DebuggerStepThroughAttribute, and the debugger will stop at the breakpoint.

[DebuggerNonUserCode]

This attributes marks a section of code as not being user code, you can then use this with the Tools->Options->Debugging->General->Enable Just My Code, option to tell the debugger not to step into the decorated code.

Jaimal Chohan
That's handy to know!
DaRKoN_
+1 Your debug-Fu is greater than mine
Chris Ballance
Didn't know about any of those. Ballin.
Nathan Taylor
it works also on property or a class
gsharp
Best approach for stepping over pesky drawing functions.
Steve
+6  A: 

You can specify a breakpoint condition (right click on the breakpoint red circle icon) so that the breakpoint stops the execution only when something interesting happens.

egapotz
This is probably a more viable answer to this question just because it can be done without decorating the code with attributes. Still, Jaimal's suggestion is pretty awesome too. :D
Nathan Taylor
I agree, that's why I voted Jaimal's answer up ..
egapotz
+5  A: 

Here's another handy one: If you are currently stopped on a break point, and you just want to run to some other point in the code, you can right-click on the line that you wish to run to and select "Run to Cursor".

JMarsch
+2  A: 

If you want to execute the code after the breakpoint, up to another line, use JMarsch's "Run to Cursor" suggestion.

If you want to SKIP the following lines, and resume execution at another point, you can use your mouse to drag the yellow arrow in the left margin of the code window - down to the line you want to execute next.

This is also useful if you want to re-execute some code that's already run - just drag the yellow arrow UP to that line. I often use this to "Step Into" code that I've already done a "Step Over" on.

"Set Next Statement" in the right-click menu has the same effect.

-Tom Bushell

Tom Bushell