Jungle Coder

The musings of a third culture coder and missionary kid

A .NET breakpoint that only breaks if a debugger is attached

This is a helpful little function that I wrote when I found out about the System.Diagnostics.Debugger.IsAttached.aspx) property. I found it useful for debugging a synchronization service that I was working on at work.

What other little utilities like this have you made?

public static class utils { 
    public static void DebugIf(Func<bool> toCheck) 
    {
        if (System.Diagnostics.Debugger.IsAttached && toCheck()) 
        {
            System.Diagnostics.Debugger.Break();
        }
    }
}
Previously: Academic Portfolio
Next: Make sure you're able to run timer based services on demand

Comments

There are no comments for this article yet.

Email:*
Name:*
Reqired fields are marked with a '*'