backgroundTaskHost.exe exits with code 1 (0x1)

蹲街弑〆低调 提交于 2019-12-05 05:40:57

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.

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.

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.

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

szuuuken

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!