私のWPFアプリは、外部DLLのメソッドを使用しています(C++、UI、ちょうどロジックで何も)このように:UIスレッドとは別で呼び出さSomeWPFMethodWPF
[DllImport("myExternDll.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
private static extern int externalMethod(string str);
int SomeWPFMethod()
{
int res;
try
{
res = externalMethod(str);
}
catch(Exception e)
{
LogError(e)
return -1;
}
return res;
}
注、(もし本件)。 DLL内の何かが間違っている場合は
私は
を持っているタイプ 'System.AccessViolationException' の未処理の例外は、例外
を発生しました。
Aアプリに設定された処理できない例外の方法を持っているが、これは何もしません:
Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
e.Handled = false;
return;
}
ShowUnhandledException(e);
}
がクラッシュからアプリケーションを防ぐために、例外を処理するために何とか可能はありますか?
externメソッドが失敗した場合、私は何もしたくありませんが、アプリケーションはまだ動作するはずです。今それは墜落した。
これは、[.NET相互運用機能と例外処理](https://blogs.msdn.microsoft.com/liviuc/2009/10/13/net-interop-and-exception-handling-in-mixed-アプリケーション/) –
[WPFのWinformsコンポーネントから未処理の例外を処理する]の可能な複製(http://stackoverflow.com/questions/8111334/handling-unhandled-exceptions-from-winforms-components-in-wpf) –
>> Thomas 、 いいえ、これはWPFではなくWinFormsで動作します – Ksice