[英]How to get timer running even when application is running in background or phone is locked in Windows Phone
[英]Windows Phone: How to keep timer running after exiting an application?
我想编写一个显示倒数计时器的应用程序。 当我按Home或搜索按钮退出应用程序时,计时器将停止,直到我返回到该应用程序为止。 这是我的代码:
public Page1()
{
InitializeComponent();
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 1, 0);
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
//Till timer is greater than 0 show timer.
}
如何在退出应用程序时以持续计数(运行)的方式使用计时器?
在ApplicationSettings
保存启动计时器的时间。 当应用恢复(激活或重新启动)后,请检查时间差异,然后从剩余时间重新启动计时器或将计时器显示为已停止。
在Windows服务中嵌入WCF或Web API服务(Windows服务计时器示例) ,使用此WCF / Web API服务,您可以控制行为而无需重新启动服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.