Consider the following example: https://github.com/StefanWickDev/UWP-FullTrust/tree/master/UWP_FullTrust_3
When the UWP app creates the AppService, it will observe the related task cancellation in order to detect the closing of the AppService. The AppService gets closed when:
- The full-trust process drops the AppServiceConnection.
- The UWP app is suspended.
The logic I want to implement is to restart the full-trust process if the connection was dropped because of the full-trust process going away (e.g. a crash), but avoid restarting if the UWP app is going to suspend. I have not found a reliable way to do this.
In App.OnTaskCanceled there's nothing in the parameters that would indicate what caused the closure (SystemPolicy for both cases). App.IsSuspending is false at that point. The App.Suspending event always happens after the App.OnTaskCanceled has been triggered.
I could start a timer and delay the restart trusting that App.Suspending gets triggered in a time-window, but I would prefer to use a less complicated way.
BTW, it is not clear to me if the UWP app can be suspended if the AppServiceConnection is open. At least VS allows me to trigger the suspend/resume using the lifecycle controls and the UWP app's Suspending/Resuming get triggered.
Suspend/resume behavior seems to be undocumented for Desktop Bridge UWP apps, so I'm essentially trying to reverse engineer how this works...