Is Debug.Print() Executed when the debugger is NOT attached?

When not debugging with visual studio i.e. just using the device normally, are Debug.Print() commands still executed?

If so, is there an easy way to disable them other than changing every Debug.Print line in each file?..Aside from adding any Preprocessor Directives like:
#if DEBUG…

@ Gismofx - Use an attribute for conditional compilation: see [url]http://www.tutorialspoint.com/csharp/csharp_attributes.htm[/url]

All of my “Debug.Print()” statements are wrapped with “if (Debugger.IsAttached)”, this way there is no chance of the debug statement being run when vs is not connected.

1 Like

This is a nice way to do it, but it seems like you need to switch the the Condition before you compile, just like using the Processor Directives. Is there some way to do this automatically?

I like this method. I guess the overhead of calling Debugger.IsAttached is [em]minimal[/em]?

When you compile your application as “release” version the macro _DEBUG is usually not defined. When you use this macro as conditional attribute all your debug print calls will be removed automatically. Best for performance and code space.