Debug mode from IDE

CJLeit

Freshman
Joined
Feb 1, 2006
Messages
32
I've got the below line of code in my program that checks if the program is running in Debug mode.

Code:
#If DEBUG Then
       msgbox(idNum)
#End If

If I compile in debug mode and run the program it gives me my message box. However if I have release mode selected in the configuration manager and then run the program from the IDE I don't get my message. I figured that whenever you ran a progrom from the IDE it would automaitcally be considered to be in debug mode, is this incorrect? If so is there a way to tell if you're running from the IDE.

Also I rarely use debug checks like this in my programs. Is there any point to ever be in debug mode if you don't use any debug symbols?

Thanks!
 
Your code only runs when you're in DEBUG mode. In RELEASE mode, your code will be ignored. I don't really get the difference between those modes except that it will result in different BUILD process.

By default if you're simply running your application without changing the mode and using the "play" button or pressing F5 then you're surely run your program in DEBUG mode.

You should be using you're code to run something you want only in DEBUG mode. Such as setting a default user name and password. Using your code you don't have to bother removing your code once you're ready to release your code.

I hope you get my point here.
 
Debug vs Release

There are two major differences between Debug and Release builds:

The most important difference is that, in a Debug build, special symbols are emitted into the compiled MSIL to help a debugger (such as Visual Studio) synchronize between MSIL instructions and the actual source code. Without these symbols it is quite possible that when an exception is thrown, the debugger highlights the wrong line of code (or none at all), as a single code statement can translate to an indeterminate number of MSIL instructions.

The other, less significant difference is that the generated MSIL code is optimized in a Release build. Since the majority of optimizations are performed on JIT compiling (when the application is executing), Release build optimizations do not generally cause a significant performance boost in my experience.

Note that both debugging symbols and optimizations can be turned on and off in both builds, so it would be possible to enable optimizations in a Debug build, or include debugging symbols in a Release build, should this be desirable.

MSDN: Debug and Release Configurations

Good luck :)
 
Re: Debug vs Release

It seems there is some confusion here between making a debug build and running in a debugger.

When you run your code in the IDE you are running the code in a debugger. You can do this with a debug build and a release build (some features require a debug build, though). This really has nothing to do with DEBUG and RELEASE builds. If you select RELEASE and run the app from the IDE, you are debugging, but you are debugging a release build.

The difference is when you select DEBUG or RELEASE from the build menu you are choosing a build configuration, or a preset set of compiler options, (which can actually be customized, and the use of the traditional "DEBUG" and "RELEASE" configurations isn't really necessary, it's just the way it is done). The default DEBUG configuration defines the DEBUG symbol (this means that code included in an #if DEBUG directive will be compiled), disables optimizations, and produces a debug database (which helps syncronize the debugger and the program, like MrPaul mentioned). The default RELEASE configuration does not define the DEBUG symbol (#if DEBUG code won't be compiled), optimizations are enabled, and no PDB (debug database) is generated.
 
Back
Top