下次应用启动时后台任务终止 [英] Background task is terminated next time app launches
问题描述
我正在使用 来自 MSDN 的后台任务代码示例 (c#).我稍微修改了代码以使其运行更长时间,以便我可以查看应用程序是否可以在下次启动时重新附加"到后台任务.我的测试表明,当应用程序第二次启动时,后台任务总是被终止.以下是测试详情:
I am playing with the Background Task code sample (c#) from MSDN. I modified the code a little bit to make it run longer, so that I can see if the application can get "re-attached" to the background task next time it is launched. My test shows that the background task always gets terminated when the application is launched for a second time. Here is the test detail:
后台任务由 SystemTriggerType.TimeZoneChange
类型的 SystemTrigger
触发,如果:
The background task is trigger by a SystemTrigger
of type SystemTriggerType.TimeZoneChange
, and it works as expected if:
- 我先启动应用程序,然后更改我的时区设置;
- 我先更改时区,然后启动应用程序;
但是如果我关闭应用程序(按 ALT+F4),然后在后台任务完成之前再次启动它.我将始终看到后台任务已终止.有时我会在输出窗口中看到类似The program '[920] backgroundTaskHost.exe: Managed (v4.0.30319)' has exited with code 1 (0x1).
"之类的消息.
But if I close the application (by ALT+F4) and then launch it again before the background task completes. I will ALWAYS see that the background task is terminated. Sometimes I see messages like "The program '[920] backgroundTaskHost.exe: Managed (v4.0.30319)' has exited with code 1 (0x1).
" in the Output window.
为什么每次再次启动应用程序时后台任务都会终止?是设计吗?还是我在这里遗漏了什么?
Why is the background task terminated every time the application is launched again? Is it the design? Or am I missing something here?
推荐答案
那是项目引用问题.
如果您在运行后台任务时退出了code 1 (0x1)
的程序,则应将后台任务项目添加到原始项目的引用中.
If you exited program with
code 1 (0x1)
when you run backgrond task, you should add the background task project into the referece of original project.
[Windows 8]BackgroundTask的崩溃问题教你如何解决参考.
这篇关于下次应用启动时后台任务终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!