2015-04-17 80 views
0

我的应用程序遇到一些崩溃(有点类似于指南针应用程序)。 Windows崩溃报告告诉我这一点:Windows手机崩溃device.Sensors.ni.dll

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

我想问一下,我一定要检查,如果加速度计已准备好(或空支票或别的东西)?

任何帮助或指导在这里表示赞赏。

回答

0

这些崩溃可能来自没有指南针的设备(是的,有这样的设备)。

你应该检查与Compass.IsSupported指南针,只有当它返回true时使用它。

+0

嗯,我明白了...我检查它,当应用程序启动。但是我认为,现在你说了这个,有时可能会崩溃,因为当他们回到应用程序时,我不检查指南针支持。我试着改变这一点。谢谢。 – Steffei