デバッガーがメモリ内で実行されていることを検出する方法はありますか?
そして、ここにフォームロードの擬似コードがあります。
if debugger.IsRunning then
Application.exit
end if
編集:元のタイトルは「メモリ内デバッガの検出」でした
次を試してください
if ( System.Diagnostics.Debugger.IsAttached ) {
...
}
これを使用してデバッガーで実行されているアプリケーションを閉じる前に、次の2つの点に注意してください。
ここで、さらに役立つように、パフォーマンス上の理由で遅延評価されたプロパティのキャッシュがある場合に、この検出を使用してデバッガーの関数がプログラムの状態を変更しないようにする方法を説明します。
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;
}
}