简洁版本:
我有一个 WinForms 应用程序,它使用 .NET 4.0 WebBrowser 控件来显示包含 Flash SWF 文件的 HTML 页面。SWF 文件通过一些 Javascript/jQuery/swf)iobject 魔术设置。我定期遇到一个 SWF 文件,该文件将导致 AccessViolationException 停止我的程序。据我所知,这发生在显示一个页面和启动另一个页面之间的清理过程中(想想网站的自动幻灯片放映)。
我添加了 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()
我的挑战是阻止该异常在屏幕上显示任何内容。