什么是导致我的WP7应用程序崩溃? [英] What's causing my WP7 app to crash?

查看:154
本文介绍了什么是导致我的WP7应用程序崩溃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在模拟器和手机本身发生了一些不明原因的崩溃。基本上当我的应用程序崩溃时,我没有任何对话框,手机返回主屏幕。



我有以下代码来显示一个MessageBox,但这是以某种方式绕过...

  //导航失败时执行的代码
private void RootFrame_NavigationFailed(object sender,NavigationFailedEventArgs e)
{
MessageBox.Show(e.Exception.ToString());
}

//未处理异常执行的代码
private void Application_UnhandledException(object sender,ApplicationUnhandledExceptionEventArgs e)
{
MessageBox.Show(e。 ExceptionObject.ToString());
}

我认为这可能与内存相关,因为我的应用程序处理大量图像。但是,我认为,仍然会被我上面未处理的异常代码所捕获。任何有关如何追踪这一点的想法将不胜感激。

解决方案

关注您的内存使用情况。 OutOfMemoryException在不调用Application_UnhandledException处理程序的情况下崩溃您的应用程序。
您可以使用一些内置方法检查当前内存使用情况。之前我曾经发布过 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();


I've had a few unexplained crashes happening on both the emulator and the phone itself. Basically when my app crashes I get no dialog box whatsoever and the phone returns to the home screen.

I have the following code to display a MessageBox but this is somehow being bypassed...

// 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());
}

The thought occurred to me that it might be related to memory, since my app deals with a lot of images. But I figure that would still be caught by my unhandled exception code above. Any ideas on how I should track this down would be appreciated.

解决方案

Keep an eye on your memory usage. An OutOfMemoryException crashes your app without calling the Application_UnhandledException handler. You can check the current memory usage with some built in methods. I blogged about this a while ago http://kodierer.blogspot.com/2010/09/windows-phone-memory-constraints.html

Here's the basic code you should add:

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();

这篇关于什么是导致我的WP7应用程序崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆