在Windows Phone 7上访问ui线程形成一个非ui线程

时间:2011-05-26 18:02:18

标签: c# windows-phone-7 invoke dispatch

  

可能重复:
  Calling NavigationService.Navigate from Accelerometer.ReadingChanged throws a NotSupportedException

嗨,

如果加速度计触发,我会尝试导航到其他页面:

void accelerometer_ReadingChanged(object sender, AccelerometerReadingEventArgs e)
        {
            //double X, Y, Z;
            if (e.X > 1.5)
            {
            NavigationService.Navigate(new Uri("/Bars/DetailBar", UriKind.Relative));
            }
       } 

但是,我收到“无效的跨线程访问”错误,我试图通过这样做来解决这个问题:

        Dispatcher.BeginInvoke( () => { 

        NavigationService.Navigate(new Uri("/Bars/DetailBar", UriKind.Relative));


        } );

和此:

        Deployment.Current.Dispatcher.BeginInvoke( () => {


        NavigationService.Navigate(new Uri("/Bars/DetailBar", UriKind.Relative));


        } ); 

但没有任何效果。你能解释我的错误吗?

0 个答案:

没有答案