如何每隔特定时间在 Windows Phone 8 上执行一个方法?
How to execute a method on Windows Phone 8 every specific time?
如何让 Windows Phone 8 app 运行 每隔特定时间(比如一分钟)使用某种方法?我希望它仅在应用程序打开时 运行,不需要后台任务。我用 C#
编写程序
你想要的是 DispatcherTimer
看这里:
MSDN : DispatcherTimer Class WP8
MSDN : DispatcherTimer Class WP runtime
记得包括
System.Windows.Threading // [for Windows Phone 8]
Windows.UI.Xaml // [for Windows Universal App]
示例来自 MSDN
private void Page_OnLoaded(object sender, RoutedEventArgs e)
{
DispatcherTimer timer = new DispatcherTimer();
timer.Tick +=
delegate(object s, EventArgs args) {
// code to execute
};
timer.Interval = new TimeSpan(0, 0, 1); // one second
timer.Start();
}
如何让 Windows Phone 8 app 运行 每隔特定时间(比如一分钟)使用某种方法?我希望它仅在应用程序打开时 运行,不需要后台任务。我用 C#
编写程序你想要的是 DispatcherTimer
看这里:
MSDN : DispatcherTimer Class WP8
MSDN : DispatcherTimer Class WP runtime
记得包括
System.Windows.Threading // [for Windows Phone 8]
Windows.UI.Xaml // [for Windows Universal App]
示例来自 MSDN
private void Page_OnLoaded(object sender, RoutedEventArgs e)
{
DispatcherTimer timer = new DispatcherTimer();
timer.Tick +=
delegate(object s, EventArgs args) {
// code to execute
};
timer.Interval = new TimeSpan(0, 0, 1); // one second
timer.Start();
}