Tim Hibbard

CEO for EnGraph software
posts - 626, comments - 1589, trackbacks - 459

My Links

News



Add to Google

Twitter












Tag Cloud

Article Categories

Archives

Post Categories

Image Galleries

EnGraph Blogs

Links

Other

Roll

Use Preprocessor Directives for better debugging

The most common use for Preprocessor Directives is to intelligently group your code using the #region … #endregion tag (sidenote: Ctrl + M, M is a great keyboard shortcut to expand and contract your regions).  Preprocessor Directives can also be used to tell the compiler which code should or should not be compiled based on the configuration environment.  Wrapping code in an #if DEBUG … #endif block will only execute if the environment is in debug mode.

This proved to be a handy way to debug a situation this morning in a multi-threaded scenario where breakpoints and Console.WriteLine were not giving me enough information.  I added a new tab with initial visibility as collapsed, set it to visible in an #if DEBUG … #endif block, and wrote events to it also in a debug block.

For situations where you want code to execute only in a production environment, use #if !DEBUG … #endif.

View MSDN’s page on Preprocessor Directives for more information.

Print | posted on Monday, June 21, 2010 1:08 PM | Filed Under [ .NET Keyboard Shortcuts ]

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: