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:
The background task is trigger by a SystemTrigger
of type SystemTriggerType.TimeZoneChange
, and it works as expected if:
- I launch the application first and then change my TimeZone setting;
- I change my TimeZone first and then launch the application;
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?
That is the project reference problem.
[Windows 8] The crash problem about BackgroundTask shows you how to resolve the reference.
If you are creating the BackgroundTask in C#, and using the Windows 8 RP, I think you may have to set the output type of the project to
WinMD
file and not class library. Are you using WinMD as the output type?