私のwinformプログラムでは、各コントロールイベントでPostsharpインターセプタークラスを使用して、try/catchブロックの繰り返しを回避しています。
カスタム ポストシャープ メソッド:
[Serializable]
public class OnErrorShowMessageBox : MethodInterceptionAspect
{
public override void OnInvoke(MethodInterceptionArgs args)
{
try
{
args.Proceed();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
args.ReturnValue = null;
}
}
}
この属性を使用します。
[OnErrorShowMessageBox]
private void txtComments_TextChanged(object sender, EventArgs e)
{
//blabla
}
これは魅力のように機能しますが、イベントで非同期を使用したいことを知っています。したがって、txtComments_textChanged は次のようになります。
[OnErrorShowMessageBox]
private async void txtComments_TextChanged(object sender, EventArgs e)
{
await //blabla
}
そして、ここで問題が発生します。インターセプターメソッドの try/catch ブロックは、非同期の場合は何もキャッチしません...どうすればよいですか? ありがとう