Reputation: 1967
Using Windows phone 8.1 silverlight Background Task is a WinRT Task.
The problem I'm facing is I'm running a background task and I want the background task to exit when the foreground App is closed or terminated. I know when closing the foreground App I can use the Application_closing method to write to isolated storage to communicate with the background task. But the real question is how do I handle the event when the foreground App goes from suspension state to terminated state. Or even if is it possible for the background task to query the status of the foreground App to the OS. Thanks you.
Upvotes: 0
Views: 185
Reputation: 3362
Unfortunately there is no way to get information about your app going from the suspended into the terminated state. That's why most articles on MSDN explicitely state that you have to save any session related data before an app is suspended.
You should always save user information and app data in the suspending event because Windows doesn’t notify apps before it terminates them. This is important because termination can occur under a variety of circumstances, such as when Windows needs to free memory or the device loses (battery) power.
https://msdn.microsoft.com/en-us/magazine/jj660301.aspx
What you could do is to implement some kind of ping mechanism where your foregound app constantly writes timestamps to the isolated storage. If these pings exceed a predefined timestamp you can assume your app was terminated and exit the background task.
Upvotes: 1