C# VS2010 Determine in application whether being debugged
Asked Answered
M

2

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.

Medley answered 7/1, 2011 at 17:47 Comment(0)
S
9

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

Scudo answered 7/1, 2011 at 17:49 Comment(1)
Thanks to both of you, never came across this one. Very useful! Thanks a lot. Unfortunately I cannot mark both as answer.Medley
A
7

System.Diagnostics.Debugger.IsAttached ?

Anytime answered 7/1, 2011 at 17:48 Comment(1)
Thanks to both of you, never came across this one. Very useful! Thanks a lot. Unfortunately I cannot mark both as answer.Medley

© 2022 - 2024 — McMap. All rights reserved.