我在我的应用程序上经历了一些崩溃(有点像指南针应用程序)。windows崩溃报告告诉我:
frame 0:
Microsoft.Devices.Sensors.ni.dll; Microsoft.Devices.Sensors.Accelerometer.Start; 0x0000006c
frame 1:
PivotApp1.ni.DLL; PivotApp1.MainPage+_start_d__0.MoveNext; 0x000001d4
frame 2:
mscorlib.ni.dll; System.Runtime.CompilerServices.AsyncMethodBuilderCore._ThrowAsync_b__3; 0x00000036我无法理解这到底意味着什么。根据我从它得到的,可能是因为加速度计。
这是我当前的代码,似乎错误是从这里的某个地方生成的:
private async void start()
{
//Check for the user agreement in use his position. If not, method returns.
if ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] != true)
{
// The user has opted out of Location.
MessageBox.Show(AppResources.main_cantuse);
Application.Current.Terminate();
}
else
{
//KOMPASS
if (compass == null)
{
// Instantiate the compass.
compass = new Compass();
// Specify the desired time between updates. The sensor accepts
// intervals in multiples of 20 ms.
compass.TimeBetweenUpdates = TimeSpan.FromMilliseconds(20);
compass.CurrentValueChanged +=
new EventHandler<SensorReadingEventArgs<CompassReading>>(compass_CurrentValueChanged);
compass.Calibrate +=
new EventHandler<CalibrationEventArgs>(compass_Calibrate);
}
try
{
compass.Start();
timer.Start();
accelerometer = new Accelerometer();
accelerometer.CurrentValueChanged +=
new EventHandler<SensorReadingEventArgs<AccelerometerReading>>(accelerometer_CurrentValueChanged);
accelerometer.Start();
}
catch (InvalidOperationException)
{
MessageBox.Show(AppResources.main_unabletostart);
}我想问一问,我是否必须检查加速度计是否已经准备好(或空检查或其他什么)?
如有任何帮助或指导,我们将不胜感激。
发布于 2015-04-17 19:49:41
这些崩溃可能是由没有指南针的设备造成的(是的,有这样的设备)。
您应该用Compass.IsSupported检查指南针,只有当它返回true时才使用它。
https://stackoverflow.com/questions/29697142
复制相似问题