我在模拟器和手机本身上都发生过一些无法解释的崩溃。基本上,当我的应用程序崩溃时,我不会看到任何对话框,并且手机会返回主屏幕。
我有以下代码来显示消息框,但这在某种程度上被绕过了......
// Code to execute if a navigation fails
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
MessageBox.Show(e.Exception.ToString());
}
// Code to execute on Unhandled Exceptions
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
MessageBox.Show(e.ExceptionObject.ToString());
}
我想到这可能与内存有关,因为我的应用程序处理大量图像。但我认为这仍然会被上面未处理的异常代码捕获。任何关于我应该如何追踪这个问题的想法将不胜感激。
密切关注您的内存使用情况。 OutOfMemoryException 会在不调用 Application_UnhandledException 处理程序的情况下使您的应用程序崩溃。
您可以使用一些内置方法检查当前的内存使用情况。我不久前在博客上谈到过这个问题http://kodieer.blogspot.com/2010/09/windows-phone-memory-constraints.html http://kodierer.blogspot.com/2010/09/windows-phone-memory-constraints.html
这是您应该添加的基本代码:
var timer = new DispatcherTimer {Interval = TimeSpan.FromSeconds(2)};
timer.Tick += (s, e) =>
{
var memuse = (long)DeviceExtendedProperties.GetValue("ApplicationPeakMemoryUsage");
var maxmem = (long)DeviceExtendedProperties.GetValue("DeviceTotalMemory");
memuse /= 1024 * 1024;
maxmem /= 1024 * 1024;
MyTextBlock.Text = String.Format("Mem usage: {0} / {1} MB", memuse, maxmem);
};
timer.Start();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)