[UWP] [XAML]如何处理后台sycn进程 [英] [UWP][XAML]How to process a background sycn process

查看:77
本文介绍了[UWP] [XAML]如何处理后台sycn进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,


我已经构建了一个Windows 10通用应用程序,该应用程序通过在线平台提供其他REST API的产品。


在某个时间间隔内,我需要强制sycn进程将任何新更新同步到客户端应用程序。


实际上,这个想法是每5分钟运行一次同步。 / p>

运行异步后台进程以便在此时间间隔调用我的  CheckForUpdate()函数的最佳方法是什么?


我应该有吗?计时器和触发计时器并运行正常任务或有更好的方法吗?


当sycn完成时,我的deifferent应用程序页面需要知道是否需要刷新或者不是


感谢您的建议和想法


问候 

解决方案

嗨wkefun,


为了在这个时间间隔调用我的CheckForUpdate()函数,运行异步后台进程的最佳方法是什么?


似乎我们应该可以使用
TimeTrigger
  后台任务。请参阅此链接中的计时器上的运行后台任务:  https://msdn.microsoft.com/en-us/windows/uwp/launch-resume/run-a-background-task-on-a-timer-


如果FreshnessTime设置为15分钟且OneShot为false,则任务将安排为从注册之日起15到30分钟之间每15分钟运行一次。如果设置为n分钟且OneShot为false,则任务将被安排
,以便在注册后的n和n + 15分钟之间每n分钟运行一次。


注意如果FreshnessTime设置为小于15分钟,则在尝试注册后台任务时会抛出异常。


我们无法每次运行同步5分钟。


从您的描述中,我们应该能够使用计时器在应用程序运行时每5分钟运行一次。当应用程序暂停时,我们不需要更新数据。我们应该能够在应用程序恢复时更新数据。当应用程序从暂停状态转换为运行状态时,会在UWP中发生一个Application.Resuming
事件。





最诚挚的问候,


Jayden Gu


Dear all,

I have build a windows 10 universal app which is presenting product from an online platform other REST api.

In a certain time interval, I need to force a sycn process for any new update to be sync down to client application.

Actually the idea is to run a sync every 5 minutes.

What is the best way to run an async background process in order to call my CheckForUpdate() function at this time interval ?

Should I have a timer and trig the timer and run a normal task or is there some better approach ?

Of course when sycn is complete, my deifferent application page need to know if a refresh is needed or not as well

thanks for advise and idea

regards 

解决方案

Hi wkefun,

What is the best way to run an async background process in order to call my CheckForUpdate() function at this time interval ?

It seems we should be able to use TimeTrigger  in the background task. Please refer the Run a background task on a timer in this link: https://msdn.microsoft.com/en-us/windows/uwp/launch-resume/run-a-background-task-on-a-timer-.

If FreshnessTime is set to 15 minutes and OneShot is false, the task will be scheduled to run every 15 minutes starting between 15 and 30 minutes from the time it is registered. If it is set to n minutes and OneShot is false, the task will be scheduled to run every n minutes starting between n and n + 15 minutes after it is registered.
Note If FreshnessTime is set to less than 15 minutes, an exception is thrown when attempting to register the background task.

That we can not run the sync every 5 minutes.

From your describe, we should be able to use timer to run the aync every 5 minutes when the app is running. When the app is suspending that we no need to update the data. We should be able to update the data when the app is resuming. There is a Application.Resuming event in UWP that it occurs when the application transitions from Suspended state to Running state.


Best Regards,

Jayden Gu


这篇关于[UWP] [XAML]如何处理后台sycn进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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