Home All Groups Group Topic Archive Search About

How to detect if program execution is in debug mode?

Author
11 Aug 2006 9:13 PM
Bob
If I'm running the executable, I need to do something, but if I am running
the program fom within Visual studio I need to use another bit of code.

Thanks for any help.

Bob

Author
11 Aug 2006 9:17 PM
Herfried K. Wagner [MVP]
"Bob" <bduf***@sgiims.com> schrieb:
> If I'm running the executable, I need to do something, but if I am running
> the program fom within Visual studio I need to use another bit of code.

Maybe the following solutions fit your requirements:

\\\
#If DEBUG Then
    Console.WriteLine("Debug mode.")
#Else
    Console.WriteLine("Release mode.")
#End If
///

Make sure that the option "Configuration settings" -> "Build" "Define DEBUG
constant" in the project properties is checked.

- and/or -

You can check if a debugger is attached:
'System.Diagnostics.Debugger.IsAttached'.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
11 Aug 2006 9:20 PM
Bob
Thanks

Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:OOQrGuYvGHA.4456@TK2MSFTNGP06.phx.gbl...
> "Bob" <bduf***@sgiims.com> schrieb:
>> If I'm running the executable, I need to do something, but if I am
>> running the program fom within Visual studio I need to use another bit of
>> code.
>
> Maybe the following solutions fit your requirements:
>
> \\\
> #If DEBUG Then
>    Console.WriteLine("Debug mode.")
> #Else
>    Console.WriteLine("Release mode.")
> #End If
> ///
>
> Make sure that the option "Configuration settings" -> "Build" "Define
> DEBUG
> constant" in the project properties is checked.
>
> - and/or -
>
> You can check if a debugger is attached:
> 'System.Diagnostics.Debugger.IsAttached'.
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://classicvb.org/petition/>
Author
16 Aug 2006 3:42 PM
Phill W.
Bob wrote:
> If I'm running the executable, I need to do something, but if I am running
> the program fom within Visual studio I need to use another bit of code.

If System.Diagnostics.Debugger.IsAttached Then
    ' Debugging
Else
    ' Running from Executable
End If

HTH,
    Phill  W.