디버거 아래에서 실행될 때 프로그램 흐름 변경
문제
디버거가 메모리에서 실행되고 있음을 감지하는 방법이 있습니까?
그리고 여기에 양식 부하 의사 코드가 있습니다.
if debugger.IsRunning then
Application.exit
end if
편집하다: 원래 제목은 "메모리 디버거 감지"였습니다.
해결책
다음을 시도하십시오
if ( System.Diagnostics.Debugger.IsAttached ) {
...
}
다른 팁
디버거에서 실행되는 응용 프로그램을 닫기 위해 이것을 사용하기 전에 명심해야 할 두 가지 사항 :
- 디버거를 사용하여 상용 .NET 애플리케이션에서 충돌 추적을 당기고 회사에 보내 주셔서 감사합니다.
- 그 수표 일 수 있습니다 사소한 패배.
이제 더 많이 사용하려면이 탐지를 사용하여 유지하는 방법은 다음과 같습니다. func eval 성능의 이유로 캐시에 게으르게 평가 된 속성이있는 경우 프로그램 상태를 변경하여 디버거에서.
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;
}
}
제휴하지 않습니다 StackOverflow