如何测试代码在调试模式下执行。
这是我想在伪代码中做的事情
if not debugMode then
Do something()
end if
您可以使用Debugger.IsAttached来确定程序是否正在被调试。
If Not Debugger.IsAttached Then
DoSomething()
End If
编辑如果您总是想在调试版本中跳过DoSomething
代码,无论是否使用调试器,请使用conditional compilation和#If,类似这样的
#IF DEBUG Then
DoSomething()
#End If
调试模式是什么意思?如果您参考调试版本,可以使用#if DEBUG
来测试:
#if DEBUG
// this is included in a debug build
#else
// this is not included in a debug build
#endif
你可以使用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