【发布时间】:2011-06-10 05:02:21
【问题描述】:
我在开发 WP7 应用程序时遇到了非常奇怪的问题,这些问题通常发生在 30m 或 1h 之后,尽管代码非常简单,几乎等于示例。模拟器没问题。
- 应用程序崩溃,没有抛出异常
- 未处理的异常:{“0xffffffff”}(是的,消息是“0xffffffff”。并且 Stacktrace 为空)
- 一旦我在获取 DateTimeOffset.Now 属性时抛出异常 (!)
- UI 线程冻结,无法终止应用程序,必须重启设备
所以在这一点上,我认为要么是 WP7 真的不稳定,要么是我的设备硬件有问题。
WP7 是否存在老化测试?像 Memtest86、Prime 和其他桌面实用程序一样?
编辑:这是导致问题的代码:
public partial class MainPage : PhoneApplicationPage
{
private Accelerometer _accelerometer;
private GeoCoordinateWatcher _gps;
public MainPage()
{
InitializeComponent();
_accelerometer = new Accelerometer();
_accelerometer.ReadingChanged += new EventHandler<AccelerometerReadingEventArgs>(_accelerometer_ReadingChanged);
_accelerometer.Start();
_gps = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
_gps.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(_gps_PositionChanged);
_gps.Start();
}
void _gps_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
Dispatcher.BeginInvoke(() =>
{
TBLocation.Text = e.Position.Location.ToString();
});
}
void _accelerometer_ReadingChanged(object sender, AccelerometerReadingEventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
TBAccelX.Text = string.Format("X: {0:F2} g", e.X);
TBAccelY.Text = string.Format("Y: {0:F2} g", e.Y);
});
}
}
<phone:PhoneApplicationPage
x:Class="AccelerometerTest2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<StackPanel>
<TextBlock Name="TBAccelX"/>
<TextBlock Name="TBAccelY"/>
<TextBlock Name="TBLocation"/>
</StackPanel>
</phone:PhoneApplicationPage>
编辑:因为我怀疑手机有问题。该应用已在另一台设备上正常运行 5 小时。
【问题讨论】:
标签: windows-phone-7