在WP7上激活电话时禁用DispatcherTimer

Ced*_*ach 2 silverlight windows-phone-7 windows-phone

我的WP7(silverlight)应用程序一直被拒绝,因为它"不应该在来电时继续振动".但是,只是对Applicaton_Deactivated事件做出反应不允许我解决问题,因为这个方法不会在来电时调用...

有问题的振动是通过a完成的DispatcherTimer,它在电话呼叫后的后台继续运行.将执行移动到主线程并没有改变任何东西.

应用程序是否继续在电话后正常运行?或者有什么方法可以阻止振动?

振动器和定时器的初始化:

vibrator = VibrateController.Default;
vibratorTimer = new DispatcherTimer();
vibratorTimer.Tick += new EventHandler(vibrateRepatedly);
vibratorTimer.Interval = new TimeSpan(0, 0, 0, 0, UIConstants.VIBRATION_INTERVAL);
vibrationSpan = new TimeSpan(0, 0, 0, 0, UIConstants.VIBRATION_DURATION);
Run Code Online (Sandbox Code Playgroud)

勾选方法:

private void vibrateRepatedly(object sender, EventArgs e)
{
    vibrator.Start(vibrationSpan);
}
Run Code Online (Sandbox Code Playgroud)

Ris*_*ara 6

在有电话呼入Obscured event叫,而不是Application_Deactivated event.您将在应用程序中收到一个模糊事件,但由于来电,传入短信或提醒,您无法区分是否存在这一事件.

以下是您获得的Obscured事件的MSDN文档的链接.有一个相应的Unobscured event你也可以检测.