Skipping code during step-through debug Visual Basic, C# .NET

By Jake Edwards | Saturday, February 13th, 2010 | Permalink | 2 Comments

When developing certain types of programs, different methods of debugging may be required in order to effectively and efficiently debug.

For example, programs with a timer iterative functions with a small interval, programs intercepting Window (WndProc) messages, or even programs with multiple hooks to the keyboard or mouse. All these type of programs have something in common…. it’s a major pain in the backside to ‘step-through’ (by default F10 in Visual Studio) without it jumping to areas non-related to the area of interest.

It’s not until recently that I discovered the DebuggerStepThrough attribute as a question answer on Stack Overflow.

Essentially, the DebuggerStepThrough attribute belongs to the Systems.Diagnostics namespace, and can be placed before almost any block of code to indicate to the debugger that it should pass/skip the block in question.

Decleration of DebuggerStepThrough in C#;

[DebuggerStepThrough()]
private void AnExampleSub()
{
    // Annoying iterative code
}

Decleration of DebuggerStepThrough in VB.NET;

[DebuggerStepThrough()] _
Private Sub AnExampleSub()
      ' Annoying iterative code
End Sub()

During debugging step through, the debugger will not visit anywhere within the subs in the examples above.

  1. your page is usful! your VB example is a bit wrong…
    _

    not
    [DebuggerStepThrough()] _

    Comment by Graham — August 31, 2012 @ 3:41 am

  2. It seems my correction got filtered out

    [Shift-Comma]DebuggerStepThrough()[Shift-period] _

    Comment by Graham — August 31, 2012 @ 3:44 am

Leave a comment