backgroundTaskHost.exe exits with code 1 (0x1)

2019-04-27 06:54发布

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?

6条回答
闹够了就滚
2楼-- · 2019-04-27 07:18

My namespace was wrong on my entrypoint. Namespace was "App.BackgroundServices", task was "ToastBackgroundTask". I just had BackgroundServices.ToastBackgroundTask when I should have had App.BackgroundServices.ToastBackgroundTask.

查看更多
闹够了就滚
3楼-- · 2019-04-27 07:33

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.

enter image description here

查看更多
Emotional °昔
4楼-- · 2019-04-27 07:35

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:

var task = BackgroundTaskRegistration.AllTasks.SingleOrDefault(i => i.Value.Name == "PushBackgroundTask");
task.Value.Unregister(true);
RegisterBackgroundTask();

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

查看更多
贪生不怕死
5楼-- · 2019-04-27 07:37

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.

查看更多
再贱就再见
6楼-- · 2019-04-27 07:38

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.

查看更多
ゆ 、 Hurt°
7楼-- · 2019-04-27 07:40

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".

查看更多
登录 后发表回答