简体   繁体   English

在UWP中要求后台任务不止一项,是否有必要?

[英]Request for background task in UWP more than one, is it necessary?

I make a library with several background tasks for UWP 8.1/10 (desktop/mobile). 我为UWP 8.1 / 10(台式机/移动设备)制作了包含几个后台任务的库。

I have 3 background tasks but I talk about one of them. 我有3个后台任务,但我只讨论其中之一。 When the app starts, I see permission request dialog: 应用启动时,我会看到权限请求对话框:

await BackgroundExecutionManager.RequestAccessAsync();

I click to allow and continue registration of background task, this part works excellent. 我单击以允许并继续注册后台任务,这部分效果很好。 Every 15 minutes I see my task in Output . 每隔15分钟,我在输出中看到我的任务。 It works perfectly. 它运作完美。

So, in near future, I want to change execution time while background task is working it creates the same task with another TimerTrigger (depends on some conditions, but it can happen), for example: 因此,在不久的将来,我想更改后台任务运行时的执行时间,它与另一个TimerTrigger创建相同的任务(取决于某些条件,但是可能会发生),例如:

  • register again with the same time in TimerTrigger 再次在TimerTriggerTimerTrigger
  • register new TimeTrigger with one per two days timer. 每两天注册一个新的TimeTrigger计时器。

I know about: 我知道:

Note Universal Windows apps must call RequestAccessAsync before registering any of the background trigger types. 注意通用Windows应用程序必须在注册任何背景触发器类型之前调用RequestAccessAsync。

So, I need use await BackgroundExecutionManager.RequestAccessAsync() every time when I try to register any of background task, does I understand it right? 因此,每次尝试注册任何后台任务时,我都需要使用await BackgroundExecutionManager.RequestAccessAsync() ,我理解吗?

In other words, I do it every time when I change/re-register TimerTrigger for the first time, then when I need to do it when: 换句话说,我每次第一次更改/重新注册TimerTrigger执行此操作,然后在需要执行以下操作时:

  • register again with the same time in TimerTrigger 再次在TimerTriggerTimerTrigger

or 要么

  • register new TimeTrigger with one per two days timer. 每两天注册一个新的TimeTrigger计时器。

Can someone help me to understand? 有人可以帮我理解吗? :) :)

PS I saw somewhere that re-registration in UWP 10 is not necessary, is it? PS我看到某处不需要在UWP 10中重新注册,对吗?

So, I need use await BackgroundExecutionManager.RequestAccessAsync() every time when I try to register any of background task, does I understand it right? 因此,每次尝试注册任何后台任务时,我都需要使用await BackgroundExecutionManager.RequestAccessAsync(),我理解吗?

Yes. 是。 Check the remarks of BackgroundExecutionManager.RequestAccessAsync method, this must be called before registering any background tasks. 检查BackgroundExecutionManager.RequestAccessAsync方法的备注,必须在注册任何后台任务之前调用此方法。

I saw somewhere that re-registration in UWP 10 is not necessary, is it? 我看到某个地方不需要重新注册UWP 10,对吗?

If you mean this method is not necessary, actually re-registration you mentioned here should be a process that first un-register and register again. 如果您认为此方法不是必需的,那么实际上您在此处提到的重新注册应该是首先注销然后重新注册的过程。 It should have nothing special with register. 寄存器应该没有什么特别的。 Only starting with Windows 10, it is no longer necessary to call this method from the UI thread. 仅从Windows 10开始,不再需要从UI线程调用此方法。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM