后台任务已取消(超出执行时间)
Background task cancelled (ExecutionTimeExceeded)
我有一个后台任务可以下载一些 JSON 数据文件,当我使用 Visual Studio 调用它时,这些文件可以完美运行。当在启动时使用 UserPresent 触发器调用后台任务时,它会被取消 (ExecutionTimeExceeded.)
有什么可以让运行后台任务无限制的吗?
可能不是,时间限制取决于触发器类型,并且 MSDN says 它可以从 30 秒到 10 分钟不等:
CPU quotas: Background tasks are limited by the amount of wall-clock usage time they get based on trigger type. Most triggers are limited to 30 seconds of wall-clock usage, while some have the ability to run up to 10 minutes in order to complete intensive tasks. Background tasks should be lightweight to save battery life and provide a better user experience for foreground apps. See Support your app with background tasks for the resource constraints applied to background tasks.
backgroundtask 应该是一个轻量级的代码——也许你可以将文件下载过程重定向到后台传输服务,并在主应用程序中做一些繁重的工作。您也可以尝试使用 MaintenanceTrigger,这个的约束条件可能较低,但一旦 phone 连接到 AC,它就会触发。
我有一个后台任务可以下载一些 JSON 数据文件,当我使用 Visual Studio 调用它时,这些文件可以完美运行。当在启动时使用 UserPresent 触发器调用后台任务时,它会被取消 (ExecutionTimeExceeded.)
有什么可以让运行后台任务无限制的吗?
可能不是,时间限制取决于触发器类型,并且 MSDN says 它可以从 30 秒到 10 分钟不等:
CPU quotas: Background tasks are limited by the amount of wall-clock usage time they get based on trigger type. Most triggers are limited to 30 seconds of wall-clock usage, while some have the ability to run up to 10 minutes in order to complete intensive tasks. Background tasks should be lightweight to save battery life and provide a better user experience for foreground apps. See Support your app with background tasks for the resource constraints applied to background tasks.
backgroundtask 应该是一个轻量级的代码——也许你可以将文件下载过程重定向到后台传输服务,并在主应用程序中做一些繁重的工作。您也可以尝试使用 MaintenanceTrigger,这个的约束条件可能较低,但一旦 phone 连接到 AC,它就会触发。