6

I would like to know if there is a programmatic way of determining at run-time if the application was launched via the debugger or by launching an installed version of the application. My app is currently being deployed via ClickOnce.

There are certain settings I would like to alter when the app is run in debug mode vs production mode.

I am aware of the build configurations solution -- I am curious if there is a programmatic way to determine this information

Thanks

sebagomez
  • 9,501
  • 7
  • 51
  • 89
cordialgerm
  • 8,403
  • 5
  • 31
  • 47
  • Have you looked at http://stackoverflow.com/questions/394816/how-to-get-parent-process-in-net-in-managed-way? Except in your case, see if the parent process is a debugger (devenv, cdb, windbg). – nithins Sep 30 '10 at 16:22

4 Answers4

11

Use Debugger.IsAttached.

It is a static method within the System.Diagnostics namespace, as you can deduce from the name, it will return true if the debugger is attached (whether it was attached after launch or not).

You can put this in the application entry point (main) in order to find out if the application was lauched with a debugger attached, but keep in mind that it can be attached at a later time.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
4

As mentioned, you can use Debugger.IsAttached. However, be aware that this doesn't necessarily mean that the application was launched by the debugger, it may have been launched normally and then a debugger was attached to the process (I don't know if the difference is relevant for you).

matiash
  • 54,791
  • 16
  • 125
  • 154
1

To tell if it has been launched in the VS Debugger:

if(System.AppDomain.CurrentDomain.DomainManager.ToString().ToLower().Contains("vshost") == true)

Aaron G
  • 11
  • 1
0

You can use: Debugger.IsAttached

The Debugger class is a class worth looking at. It contains some nice goodies.

GvS
  • 52,015
  • 16
  • 101
  • 139