有没有办法检测内存中是否运行了调试器?
这里是Form Load伪代码。
if debugger.IsRunning then
Application.exit
end if
编辑: 原标题为“检测内存中的调试器”
尝试以下方法
if ( System.Diagnostics.Debugger.IsAttached ) {
...
}
private object _calculatedProperty;
public object SomeCalculatedProperty
{
get
{
if (_calculatedProperty == null)
{
object property = /*calculate property*/;
if (System.Diagnostics.Debugger.IsAttached)
return property;
_calculatedProperty = property;
}
return _calculatedProperty;
}
}
有时我也会使用这种变体来确保我的调试器逐步执行不会跳过评估:
private object _calculatedProperty;
public object SomeCalculatedProperty
{
get
{
bool debuggerAttached = System.Diagnostics.Debugger.IsAttached;
if (_calculatedProperty == null || debuggerAttached)
{
object property = /*calculate property*/;
if (debuggerAttached)
return property;
_calculatedProperty = property;
}
return _calculatedProperty;
}
}