I have a Windows Store application that I am creating that has a Windows Runtime Component for a background task.
The solution builds with no problems in Visual Studio but when the background task is triggered, it always fails with the message "The program '[4204] backgroundTaskHost.exe' has exited with code 1 (0x1)."
The reference to the project containing the background task is in the main project and I am setting the entry point, so I don't know what the problem is. How do I get more information as to why the program is exiting?
My namespace was wrong on my entrypoint. Namespace was "App.BackgroundServices", task was "ToastBackgroundTask". I just had
BackgroundServices.ToastBackgroundTask
when I should have hadApp.BackgroundServices.ToastBackgroundTask
.In my case it was issue with incorrect target version of Windows Runtime component. Then I changed it to version of UWP project i.e 10240.
I had (and have) the same problem, but i did notice only in the first run of my app after starting the emulator that my code runs, but the backgroundtask exits also with 1.
My solution to this is every time i start the app i unregister and reregister the Task:
This allows my code to execute every time but, the backgroudTask exits always with 1.
I found this link "how to debug backgroundtask" but until now i had no luck finding the problem
Try deleting everything from the bin and obj folder of the windows runtime project and rebuild the project in visual studio. It may solve your problem.
I was calling an an asynchronous method that returned void. I changed that method to return a Task and used await when I called it. The task runs correctly now.
I found this post
It makes a suggestion to check the project's properties and change (if the case) the Output type from "Class Library" to "Windows Runtime Component".