How-to find if we're in Debug or Release mode

  • Thread starter Thread starter Saber
  • Start date Start date
S

Saber

Is there a way to find out in which mode we are?

What can I write instead of "ItIsDebugMode" in this condition?

if (ItIsDebugMode)
{
//write something in somefile
}
 
Is there a way to find out in which mode we are?

What can I write instead of "ItIsDebugMode" in this condition?

if (ItIsDebugMode)
{
//write something in somefile
}

Assuming you define the symbols in the default way:

#if DEBUG
// We're in debug mode
#else
// We're not
#endif
 
When I press F5, when I run the exe program, when I run the program in
Release mode and even when I publish the program and run it, I get "deb!"
message!
what's wrong?

#if DEBUG

MessageBox.Show("deb!");

#else

MessageBox.Show("rel!");

#endif


The MessageBox.Show("rel!"); in VS-2005 is gray.
 
When I press F5, when I run the exe program, when I run the program in
Release mode and even when I publish the program and run it, I get "deb!"
message!
what's wrong?

#if DEBUG

MessageBox.Show("deb!");

#else

MessageBox.Show("rel!");

#endif

The above is a *compile-time* check - it decides whether you've *built*
it in debug mode or release mode. That's a different decision between
whether you're running in a debugger or not.
 
#if DEBUG
The above is a *compile-time* check - it decides whether you've *built*
it in debug mode or release mode. That's a different decision between
whether you're running in a debugger or not.

I'm a bit confused now!
I want to check if I run the program in debug mode by pressing F5 do job x
and if the program is in release mode, or installed through setup do job y.
is it possible?
 
I'm a bit confused now!
I want to check if I run the program in debug mode by pressing F5 do job x
and if the program is in release mode, or installed through setup do job y.
is it possible?

To reiterate, there are two things here:

1) Did you build as debug or did you build as release?
2) Are you running with a debugger attached or not?

Use #if DEBUG to determine 1), and use Debugger.IsAttached for 2).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top