Press "Enter" to skip to content

Windows IoT background app

I’m working on a Windows UWP webserver for hosting REST api’s. Today I tried to move from a headed to a headless demo application, but that didn’t go as smooth as I hoped.

It should be quite straight forward:

  • Download the background app template
  • Create a new “Background Application (IoT)” project
  • Implement the StartupTask
  • That’s it…

Within a few minutes I got the project ready, copied some statements from my headed app, added the deferral part and pressed F5. BAM, error:

The program '[3012] backgroundTaskHost.exe' has exited with code 1 (0x1).

Deployment error’s, well that last time I got those I had different SDK’s on the Pi and Visual Studio. Flashed the SD card again, just to be sure I didn’t screw some settings up. Put the Pi in headless mode again and checked if msvsmon.exe (remote debugger) was running. All looked great, so let’s deploy again. Same story… this went on for hours. The most frustrating part was that this all felt too familiar, I already faced this issue before but never noted the actual solution.

In the end I found the issue, and my punctuality was my bottleneck. The way I create projects was the problem. I’m used to name the project without any namespace format, and edit the project file just after creating to fix the default namespace and assembly name. This way my project will have a short name on disk and in my solution.

The problem is this piece of xml in the Package.appxmanifest:

<Extension
	Category="windows.backgroundTasks" 
	EntryPoint="BackgroundApplication1.StartupTask">
	
	<BackgroundTasks>
		<iot:Task Type="startup" />
	</BackgroundTasks>
</Extension>

You won’t find this baby when you open the manifest in the default editor, you need the raw xml to edit this. As you can see the EntryPoint should have been edited to reflect my new namespace.

  • Amadeus Wieczorek

    Good job bringing in the headless mode! I just wanted to give you heads up that there is a node.js for Universal Windows at https://github.com/ms-iot/ntvsiot/ but they don’t support headed mode. btw the formatting is off in the code snippet

  • Tom Kuijsten

    Hi Amadeus, thanks for your comment, the formatting is fixed. What do you mean with node.js for UWP? Could that help me with a background app?

  • Jean-Paul Blanc

    Big thanks, you saved me hours. I’am a beginner and I have to rename my project because I use invalid caracters inside, and I just don’t rename the stating point.