短縮版:
.NET 4.0 WebBrowser コントロールを使用して Flash SWF ファイルを含む HTML ページを表示する WinForms アプリがあります。SWF ファイルは、Javascript/jQuery/swf)iobject マジックによってセットアップされます。定期的に、プログラムを停止させる AccessViolationException を引き起こす SWF ファイルに出くわします。私が知る限り、これはあるページを表示してから別のページを開始するまでのクリーンアップ中に発生します (Web サイトの自動スライドショーを考えてみてください)。
AppDomain.CurrentDomain.UnhandledException および Application.ThreadException ハンドラーを追加しましたが、画面にダイアログが表示されたままプログラムが停止します。ダイアログが表示されないようにしたいのですが、これらの種類の例外をキャッチして抑制するにはどうすればよいですか? プログラムなどを再起動できますが、ダイアログが表示されません。
血まみれの詳細:
上記の例外ハンドラがあり、InvokeScript() を介して WebBrowser DOM で動作を呼び出している場所にいくつかの try/catch ロジックを加えています。しかし、私が用意したものは何も呼び出されないようです。
生成された例外は次のようになります。
Faulting application name: MyProgram.exe, version: 1.0.0.0, time stamp: 0x50096c59
Faulting module name: Flash64_11_3_300_257.ocx, version: 11.3.300.257, time stamp: 0x4fc81d71
Exception code: 0xc0000005
Fault offset: 0x000000000022b1db
Faulting process id: 0x10d0
Faulting application start time: 0x01cd668d0db086f8
Faulting application path: C:\Users\AUser\AppData\Local\Apps\2.0\AWMVPDR4.HEJ\Z9EP5M32.MQ4\mmm...tion_2c82cc3ef3e7d3e9_0001.0000_6ffd6d2ca43477ab\MyProgram.exe
Faulting module path: C:\Windows\system32\Macromed\Flash\Flash64_11_3_300_257.ocx
Report Id: a9f6977f-d284-11e1-a447-00187d1f4237
そしてこれ:
Application: MyProgram.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
Stack:
at System.Windows.Forms.UnsafeNativeMethods+IDispatch.GetIDsOfNames(System.Guid ByRef, System.String[], Int32, Int32, Int32[])
at System.Windows.Forms.HtmlDocument.InvokeScript(System.String, System.Object[])
at MyProgram.InvokeScriptExtension+<>c__DisplayClass2.<InvokeScript>b__0()
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(System.Object)
at System.Threading.ExecutionContext.runTryCode(System.Object)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.WebBrowserBase.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.WebBrowser.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG ByRef)
at System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr, Int32, Int32)
at System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, System.Windows.Forms.ApplicationContext)
at System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32, System.Windows.Forms.ApplicationContext)
at MyProgram.Program.Main()
私の課題は、その例外が画面に何も表示されないようにすることです。