是UnhandledException正常工作在Windows Phone上的所有情况?正常、情况、工作、UnhandledException

2023-09-04 03:46:59 作者:深忆病人

在我的Windows Phone应用程序,我用 Application.UnhandledException 来捕获所有未处理的错误。如果那样的错误的情况,然后我的应用程序显示了一个简单的的MessageBox 与通过电子邮件发送错误报告给开发者的请求。它看起来是这样的:

In my Windows Phone app I use Application.UnhandledException to catch all unhandled errors. If that kind of error happens then my app shows a simple MessageBox with a request to send an error report to developers via email. It looks like this:

protected virtual void OnUnhandledException(
    object sender, ApplicationUnhandledExceptionEventArgs e)
{
    Deployment.Current.Dispatcher.BeginInvoke(() =>
        {
            var result = MessageBox.Show(
                "Would you like to send a report to developers?", 
                "Error", 
                MessageBoxButton.OKCancel);

            if (result == MessageBoxResult.OK)
            {
                var task = new EmailComposeTask();
                task.To = "feedback@site.com";
                task.Subject = "Error";
                task.Body = 
                    e.ExceptionObject + "\n" + e.ExceptionObject.StackTrace;
                task.Show();

                e.Handled = true;
            }
        });
}

在大多数情况下,一切工作正常。

In most cases all works fine.

但许多用户抱怨说,有时候应用程序根本没有崩溃的消息。我在我的开发者中心有些崩溃报告,但这些报告有非常少量的有用信息。我不明白什么样的错误可能导致此。我只是有一些错误的后台线程之一发生的假设。

But many users complains that sometimes the app simply crashes with no messages. I have some crash reports in my developer's dashboard but these reports have a very small amount of useful information. And I can't understand what kind of error can cause this. I only have an assumption that some error happens in one of background threads.

Application.UnhandledException 正常工作在所有情况下?难道一些例外留未处理的?有什么可以在上述情况下做些什么呢?

Is Application.UnhandledException works properly in all cases? Could some exceptions stay unhandled? What can be done in situation described above?

感谢。

推荐答案

此外,在其他的答案了点,你不能保证调度程序仍在运行,或者在UI线程会再次执行。

In addition to the points in the other answers, you can't guarantee the Dispatcher is still running or that the UI thread will execute again.

当然,任何试图做几乎任何事情都可能,如果应用程序或操作系统是在一个糟糕的状态(尤其是内存不足)失败。所以,少你做的更好 - 这样,你就不会弄乱的崩溃报告,手机收集并上传到商店

Of course any attempt to do almost anything could fail if the app or OS is in a bad state (especially with OutOfMemory). So the less you do the better - that way you won't mess up the crash reports that the phone collects and uploads to the Store.

您应该改为写异常详细信息,以 IsolatedStorage 和检测过去异常的presence在下一次启动您的应用程序。

You should instead write the exception detail to IsolatedStorage and detect the presence of a past exception the next time you start your app.