2009-08-12 97 views

回答

18

您可以使用Debugger.IsAttached判断程序是否正在调试该怎么办。

If Not Debugger.IsAttached Then 
    DoSomething() 
End If 

编辑如果你总是想跳过的调试版本DoSomething代码,无论是否正在使用调试器,使用conditional compilation#If,像这样

#IF DEBUG Then 
    DoSomething() 
#End If 
9

你是什么意思与调试模式?如果你指的调试版本,你可以使用#if DEBUG测试为:

#if DEBUG 
    // this is included in a debug build 
#else 
    // this is not included in a debug build 
#endif 
1

可以使用的IsDebuggerPresent功能

<DllImport("kernel32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> _ 
Public Shared Function IsDebuggerPresent() As Boolean 
End Function 

if not isDebuggerPresent() then 
Do something() 
end if