在Windows商店应用刷新数据 [英] Refresh data in windows store app

查看:179
本文介绍了在Windows商店应用刷新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林创建Windows商店应用,有一些Web服务calls.Currently我用一个按钮事件,使web服务电话,但我希望应用程序自动做到这一点,每5分钟。
按钮事件现在摆在MainPage.xaml.cs中
什么是执行此是否有在Windows应用商店中的应用程序的计时器事件?



的最佳方式

 公共异步无效GetWebServiceDataButton(对象发件人,RoutedEventArgs E)
{
........
...... ...
检索Web服务
}


解决方案<数据/ DIV>

这是一个有点吃不消代码粘贴在这里,所以我会先添加相应的链接,我会为使用HTML / JS以及那些。



有关使用这些HTML / JS见:
在Windows 8应用使用的setTimeout计时器



使用CS / XAML虽然你仍然可以使用JS这个取决于你如何要做到这一点:$ b​​ $ b 如何提交使用定时器



有关重复计时器看到工作项目:
如何创建



周期性的工作项目现在你需要这甚至发生在应用程序没有运行?
如果是这样,那么你需要在哪个最运行每隔15分钟左右
创建并注册一个后台任务



因此,一个基本的情况是下面的(从在MSDN页),但如果你想一个方法来取消它,这就是只要还有在网站上。请注意,这将停止运行时,你的申请被暂停或终止,这是当你的应用程序已关闭或不再围绕五秒钟激活的应用程序。

  
变种周期= TimeSpan.FromMinutes(5);

VAR定时器= ThreadPoolTimer.CreatePeriodicTimer((来源)=>
{
//做你的查询/在这里工作
Dispatcher.RunAsync(CoreDispatcherPriority.High,
()=>
{
//现在的工作已经完成,安全的访问UI组件在这里向他们
});
},周期);


Im creating a windows store app that has some webservice calls.Currently i use a button event to make the webservice calls, but i want the app to do this automatically every 5 minutes. The button event is now placed in MainPage.xaml.cs What is the best way to perform this are there any timer event in windows store apps?

  public async void GetWebServiceDataButton(object sender, RoutedEventArgs e)
    {
     ........
     .........
     Retrieve data from web service
    }

解决方案

It's a bit much code to paste here so I'll add the appropriate links first and I'll provide for those using HTML/JS as well.

For those using HTML/JS See: Timers using setTimeout in a Windows 8 app

Using cs/xaml although you can still use js for this depending how you want to accomplish this: How to submit a work item using a timer

For repeating timers see: How to create a periodic work item

Now in your case do you need this to happen even when the application is not running? If so, then you'll need a background task which runs at most once every 15 minutes or so Create and register a background task

So a basic scenario is the following (from the msdn pages) but if you want a way to cancel it, that's provided there as well on the site. Note this will stop running when your application is suspended or terminated which is when your application has been closed OR is no longer the active application for around five seconds.


var period = TimeSpan.FromMinutes(5);

var timer = ThreadPoolTimer.CreatePeriodicTimer((source) =>
    {
        //do your query/work here
        Dispatcher.RunAsync(CoreDispatcherPriority.High,
        () =>
        {
           // Now that work is done, safely access UI components here to update them
        });
    }, period);

这篇关于在Windows商店应用刷新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆