オーバーヘッドを減らしてもう一度試してみましょう。
例外が CorruptedStateException かどうかを判断する方法は?
私が知っていることから、すべての CorruptedStateExceptions が (排他的に) 継承する共通のスーパークラスはなく、それらを識別するために使用できる他のプロパティ/フラグ/属性は見つかりませんでした。
今のところ、私ThirdPartyCall
が思い付くことができる最善の方法は、2 つのステップで作業することです。例外をキャッチする場合は CSE ではなく、キャッチするだけの場合は 1 つです。[HandleProcessCorruptedStateExceptions]
[SecurityCritical]
ThirdPartyCallInternal
ThirdPartyCallInternal
ThirdPartyCall
[HandleProcessCorruptedStateExceptions]
[SecurityCritical]
public static void ThirdPartyCall()
{
bool thrownExceptionIsCorruptedState = true;
try
{
ThirdPartyCallInternal(ref thrownExceptionIsCorruptedState);
}
catch (Exception ex)
{
if (thrownExceptionIsCorruptedState)
{
//This is pretty much the only thing we'd like to do...
log.Fatal("CorruptedStateException was thrown",ex);
}
throw;
}
}
private static void ThirdPartyCallInternal(ref bool thrownExceptionIsCorruptedState)
{
try
{
ThirdPartyLibrary.DoWork();
}
catch (Exception)
{
//Exception was caught without HandleProcessCorruptedStateExceptions => it's not a corruptedStateException
thrownExceptionIsCorruptedState = false;
throw;
}
}
例外がアプリケーションをダウンさせる CorruptedStateException であるかどうかを判断する他の (よりクリーンで簡単な...) 方法はありますか?