To use the UWP application for a headless raspberry Pi 2 with Windows IOT Core IOT, we can use a background application template that basically creates a new UWP application with only a background job that runs when it starts:
<Extensions> <Extension Category="windows.backgroundTasks" EntryPoint="BackgroundApplication1.StartupTask"> <BackgroundTasks> <iot:Task Type="startup" /> </BackgroundTasks> </Extension> </Extensions>
To keep the application running, we can use the following startup code:
public void Run( IBackgroundTaskInstance taskInstance ) { BackgroundTaskDeferral Deferral = taskInstance.GetDeferral();
Thus, the application continues to work, and the OS will not kill the application after any timeout in the IOT universe.
So far so great.
However: I want to be able to properly close the background application when the device turns off (or the application "gently" closes.
In a βnormalβ UWP application, you can subscribe to the OnSuspending event.
How can I be notified of an imminent close / close in this background scenario?
Help is much appreciated. Thanks in advance! -Simon
Simon mattes
source share