7

Is there a chance to determine in an C# application whether it is currently being debugged? The idea is to ignore e.g timeouts, or to provide additional information.

Just to make this clear, I am not talking about the conditional compiler flag DEBUG. This allows me to decide how the code shall be compiled. It gives no information about whether it is run in a debugger or not.

I need to decide at runtime, not at compile time.

Horst Walter
  • 13,663
  • 32
  • 126
  • 228

2 Answers2

9

You can use the Debugger.IsAttached flag to determine this.

Julien Roncaglia
  • 17,397
  • 4
  • 57
  • 75
Matthew Abbott
  • 60,571
  • 9
  • 104
  • 129
  • Thanks to both of you, never came across this one. Very useful! Thanks a lot. Unfortunately I cannot mark both as answer. – Horst Walter Jan 07 '11 at 18:08
7

System.Diagnostics.Debugger.IsAttached ?

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
  • Thanks to both of you, never came across this one. Very useful! Thanks a lot. Unfortunately I cannot mark both as answer. – Horst Walter Jan 07 '11 at 18:07