BackgroundTaskHost.exe terminates with code 1 (0x1)

I have a Windows Store application that I am creating with a Windows Runtime component for a background task.

The solution was built without problems in Visual Studio, but when starting a background task it always fails when the message "Program" [4204] backgroundTaskHost.exe "came out with code 1 (0x1)".

The link to the project containing the background tasks is in the main project, and I set the entry point, so I don’t know what the problem is. How to get additional information about why the program exits?

+6
source share
6 answers

I called the asynchronous method that void returned. I modified this method to return the task and use it when I called it. Now the task is performed correctly.

+2
source

In my case, this is a problem with the wrong target version of the Windows Runtime component. Then I changed it to the version of the UWP project ie 10240.

enter image description here

+2
source

My namespace was wrong at my entry point. The namespace was "App.BackgroundServices", the task was "ToastBackgroundTask". I only have BackgroundServices.ToastBackgroundTask when I should have App.BackgroundServices.ToastBackgroundTask .

+2
source

I had (and I have) the same problem, but I noticed only in the first launch of my application after starting the emulator that my code was working, but backgroundtask also exited from 1.

My solution for this is that every time I run the application, I unregister and re-register the task:

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

This allows me to execute my code every time, but backgroudTask always exits from 1.

I found this link how to debug backgroundtask , but so far I’m not lucky to find the problem

+1
source

I found this post

It suggests checking the project properties and changing (if any) the type of output from the "Class Library" to "Windows Runtime Component."

+1
source

Try to remove everything from the bin and obj folder during the execution of the Windows project and rebuild the project in visual studio. This may solve your problem.

0
source

Source: https://habr.com/ru/post/972937/


All Articles