简体   繁体   English

Windows Phone:退出应用程序后如何保持计时器运行?

[英]Windows Phone: How to keep timer running after exiting an application?

I want to write an app to show a countdown Timer. 我想编写一个显示倒数计时器的应用程序。 When I exit the application by pressing Home or search buttons timer will stop till I go back to the application. 当我按Home或搜索按钮退出应用程序时,计时器将停止,直到我返回到该应用程序为止。 Here is my Code: 这是我的代码:

 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.
}

How can I use the timer in a way that it keeps counting (running) even when I exited the application? 如何在退出应用程序时以持续计数(运行)的方式使用计时器?

Save the time when you started the timer in the ApplicationSettings . ApplicationSettings保存启动计时器的时间。 When the app resumes (activated or re-launched), check the time diff and either restart the timer from the remaining time or show the timer as stopped. 当应用恢复(激活或重新启动)后,请检查时间差异,然后从剩余时间重新启动计时器或将计时器显示为已停止。

在Windows服务中嵌入WCF或Web API服务(Windows服务计时器示例) ,使用此WCF / Web API服务,您可以控制行为而无需重新启动服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 即使应用程序在后台运行或手机在Windows Phone中被锁定,如何使计时器运行 - How to get timer running even when application is running in background or phone is locked in Windows Phone Windows Phone 7使应用程序在后退按钮上运行 - windows phone 7 keep application running on back button Windows注销后如何继续运行C#应用程序 - how to keep running C# application after windows log off 如何使我的位置服务在Windows Phone芒果应用程序的每一页上运行 - How to keep my Location Services running on every page of my Windows Phone mango application 如何在Windows Phone中暂停计时器? - How to pause timer in windows phone? 保持Windows服务在没有计时器的情况下运行 - Keep a Windows Service running without a timer 关闭Windows XP后,C#应用程序继续运行 - C# application keep running after closing windows XP 如何使您的Windows Phone 7.5应用程序位于顶部 - How to keep you Windows Phone 7.5 application on top 如何在应用程序缩小或在后台运行时保持计时器运行(C#Windows 10通用应用程序) - How to keep a timer running when app is minised or in the background (C# Windows 10 universal app) 如何在计算机重新启动后保持 Windows 服务运行? - How to keep Windows Service running after computer is restarted?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM