在 Windows Phone 中持续更新数据的最佳方式?
我正在尝试创建一个应用程序,该应用程序将从 Web API 获取数据并显示它,然后每 5 秒左右持续刷新数据,但我不知道执行此操作的最佳方法。
我的第一个想法只是一个简单的计时器,做一些类似于 这个问题,但我担心我可能会把它搞砸,并让计时器在不应该的情况下继续在后台运行(就像用户离开页面一样)。我是否担心一些实际上不会发生的事情?这是做我想做的事情的好方法,还是有更有效/安全的方法来做到这一点?
I'm trying to create an application that will fetch data from a web API and display it, then continuously refresh the data every 5 seconds or so, but I don't know the best way to go about doing this.
My first thought was just a simple timer, doing something like what was done in this question, but I'm worried that I may mess it up and have the timer continue running in the background when it shouldn't be (like if the user leaves the page). Am I worried over something that isn't going to actually happen? Is this a good way to go about doing what I'm trying to do, or is there a more efficient/safe way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您导航到应用程序外部时,计时器将不会继续,但是当您导航到应用程序内的另一个页面时,计时器将继续。您可以通过这种方式防止它:
此外,如果您只是检查大多数时间未更改的数据,请考虑使用 推送通知。
When you navigate outside app, timer will not continue, but when you navigate to another page inside app, timer will continue. You can prevent it this way:
Moreover, if you are just checking for data which most time is not changed, consider using push notifications.