2012-04-03 49 views
2

我知道#debug指令,但是在调试模式下编译代码时会使用这个指令。Visual Studio和.net,在代码中执行操作的任何方式 - 仅在调试时才执行?

有没有办法检测代码是否正在使用标准的.net调试器进行调试,并创建一些逻辑呢?

例如

if (isDebugging) 
{ 
    //change value of variable 
} 

预先感谢。

编辑:失败这我猜下一个逻辑的方法会建立一个插件,但我只是首先检查明显/更容易的路线。

+1

if(Debugger.IsAttached)看起来可以工作。 – 2012-04-03 10:34:04

+1

if(System.Diagnostics.Debugger.IsAttached)? c#http://bytes.com/topic/c-sharp/answers/252477-debug-mode,cheerios! – 2012-04-03 10:42:21

+0

可能的重复:[如何在ASP.NET中以调试模式执行代码](http://stackoverflow.com/questions/1734741/how-to-execute-code-only-in-debug-mode-in-asp -净) – 2012-04-03 13:07:46

回答

0

Debugger.IsAttached做了诡计。

相关问题