Reputation: 29498
In visual studio when debugging code, if you hover over a property, the body of that property will be executed. When that code is executing is it possible to determine that it is being executed due to the debugger and not due to normal code execution?
To be clear, I'm not looking for Debugger.IsAttached. I'm looking for something that I would name "Debugger.IsPaused". Does anything like that exist?
I was hoping that looking at the CurrentThread would reveal something, like being named "Debugger Thread" or having a ManagedThreadID that was meaningful, but the thread is unnamed and the managed thread id is not special.
Upvotes: 3
Views: 200
Reputation: 1783
You cannot find out if your process is being stopped in the debugger basically because your code is not being executed.
As for special cases of expression value evaluation in debugger (Visual Studio) - the following happens: the active-in-debugger thread of your process is being hijacked by the debugger and then some code generated by Visual Studio expression evaluator gets executed by your thread. After the evaluation is complete, your thread is stopped again and its state is left unchanged as it was before evaluation. This process is called "funceval". Theoretically, you could somehow analyse call stack trace in your function to find out if it is being called through funceval, but I suspect this is hardly possible due to unmanaged nature of the CLR debugger.
You can read more about funceval more in the corresponding category of Mike Stall's comprehensive CLR debugging blog: http://blogs.msdn.com/b/jmstall/archive/category/11475.aspx
Upvotes: 2