2009-08-12 99 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