WP8应用程序如何处理从Webbrowser.InvokeScript在另一个线程上引发的异常



我正在尝试将AdMob广告合并到我的WP8应用程序中,并注意到一定比例的广告(通常是基于文本的广告,但并不总是)会引发以下异常:

A first chance exception of type 'System.SystemException' occurred in Microsoft.Phone.Interop.ni.dll

我做了很多挖掘,发现一些admob间隙在尝试使用InvokeScript(下面的stacktrace)时出现了问题。

Microsoft.Phone.Interop.ni.dll!Microsoft.Phone.Controls.NativeMethods.ValidateHResult(int hr)
Microsoft.Phone.Interop.ni.dll!Microsoft.Phone.Controls.WebBrowserInterop.InvokeScript(string scriptName, string[] args)
Microsoft.Phone.ni.dll!Microsoft.Phone.Controls.WebBrowser.InvokeScript(string scriptName, string[] args)
GoogleAds.DLL!A.c778af7b26605e0bb7fadf1547d7f5530.c379e3fb7ee502b62de5eee847f1352a2(string c1966769b4ad56530475a20642e40c06c)

这可能是因为有些广告格式不好(只是猜测),但我想知道当抛出异常时,我是否有办法抓住它(到目前为止运气不佳)。Admob调用使用beginInvoke,因此它们不在同一个线程上,因此下面的典型模式不会导致断点被命中。我已经确保选中了visualstudio选项"当异常跨AppDomain或本机/托管边界时中断"。

在应用程序()下

UnhandledException += Application_UnhandledException;

处理方法:

private void Application_UnhandledException(object sender,     ApplicationUnhandledExceptionEventArgs e)
{
    if (System.Diagnostics.Debugger.IsAttached)
    {
        // An unhandled exception has occurred; break into the debugger
        System.Diagnostics.Debugger.Break();
    }
}

有什么办法可以捕捉到这些异常情况吗?

我找到了这个问题的解决方案,它让我有了一个异常处理程序,即使在不同的线程上也会调用它。

http://www.markermetro.com/2013/01/technical/handling-unhandled-exceptions-with-asyncawait-on-windows-8-and-windows-phone-8/

最新更新