Refresh data in windows store app

守給你的承諾、 提交于 2019-12-08 02:44:27

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);

You could use a System event background task, if you're looking for this to work while your app is not running.

It will wake up a minimum of every 15 minutes, even if your app is not running.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!