• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

Finding out the mode of the execution

Hi,
I'm trying to track the build mode when running an application to figure out the mode is debug or not. I tried #if(DEBUG) but doesn't look like it's working.

regards,
Saranga Amarasinghe
Analyst/Programmer
#if (DEBUG)
     shellStatusStrip.BackColor = Color.Yellow;
#endif

Open in new window

0
szaranger
Asked:
szaranger
  • 4
  • 4
1 Solution
 
JimBrandleyCommented:
This works:
#if DEBUG
   System.Diagnostics.Debug.WriteLine("We are in debug mode.");
#endif

Jim
0
 
cookreCommented:
0
 
JimBrandleyCommented:
cookre - That will tell you if a debugger is currently attached to the process, not the build mode.

Jim
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
szarangerAuthor Commented:
When I compile it in release and run , the same code appears
0
 
szarangerAuthor Commented:
if (System.Diagnostics.Debugger.IsAttached)
            {
                #if (!DEBUG)
                    shellStatusStrip.BackColor = Color.Yellow;
                #else
                    shellStatusStrip.BackColor = Color.Blue;                        
                #endif
                }
0
 
szarangerAuthor Commented:
Jim,
      I tried the following code in both debug mode and release mode. But both modes seem to execute
only shellStatusStrip.BackColor = Color.Yellow;

#if !DEBUG
                    shellStatusStrip.BackColor = Color.Yellow;
 #else
                    shellStatusStrip.BackColor = Color.Blue;                        
#endif
0
 
JimBrandleyCommented:
In order to use  DEBUG, you need to set your project to define that name for debug builds, and not release builds. Right-click your solution in the solution explorer, and select Properties from the context menu. In the window that opens, select the Build Tab. At the top of that pane, select the Debug build configuration, then check the "Define DEBUG Constant" checkbox. Select the Release configuration, and make sure that checkbox is unchecked. Save your changes.

Then in your code,
#if DEBUG
                   shellStatusStrip.BackColor = Color.Blue;                        
#else
                    shellStatusStrip.BackColor = Color.Yellow;
#endif

Jim
0
 
szarangerAuthor Commented:
Yep it's working now.. Thanks Jim
0
 
JimBrandleyCommented:
My pleasure. Good luck.

Jim
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now