当我的 uwp 应用程序暂停时,如何 运行 一个很长的 运行ning 任务?

How to run a long running task when my uwp application is suspended?

我有一个 UWP 应用程序,它执行一些长达 1 或 2 小时的长 运行ning 任务。当我最小化我的 UWP 应用程序时,我的应用程序的状态变为暂停,我的长 运行ning 任务也被暂停。我想知道我是否可以在我的 UWP 应用程序暂停时让我的长 运行ning 任务继续工作。我希望这项工作适用于台式机、平板电脑和笔记本电脑。

this post来看,如果桌面没有墙电,使用ExtendedExecutionSession只能运行一个任务不到10分钟;对于平板电脑或笔记本电脑,只要屏幕打开,它就可以 运行,取决于电池。

我还调查了后台任务或后台传输 - 后台任务似乎不支持像我这样的工作;而后台传输只支持文件传输。

我现在能看到的唯一选项是 win32 应用程序,我可以将它作为我的 uwp 应用程序的一部分。我可以为 win32 应用程序启动一个进程,通过应用程序服务连接将信息从 uwp 传递到这个 win32,然后当我的 uwp 应用程序被挂起时,我的 win32 应用程序可以继续处理长期的 运行ning 任务。在我漫长的 运行ning 任务完成后,我可以激活我的 uwp 应用程序以恢复。

这里还有其他选择吗?当我的 uwp 挂起时,使用 win32 进程来 运行 我的长 运行ning 任务有什么不对吗?我有实验代码将它们打包在一个appx中,uwp可以启动win32进程,并且它们可以相互通信。欢迎任何意见或疑虑或建议!

如果您正在为个人 use/sideloading 而不是应用程序商店编写 UWP 应用程序.. 这个 MSDN link 回答了您的问题。

来自link: "If you are developing an app that is not intended to be submitted into the Microsoft Store, then you can use the ExtendedExecutionForegroundSession with the extendedExecutionUnconstrained restricted capability so that your app can continue to run while minimized, regardless of the energy state of the device.  "