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

LVL 2
szarangerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
szarangerAuthor Commented:
Yep it's working now.. Thanks Jim
0
JimBrandleyCommented:
My pleasure. Good luck.

Jim
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.