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 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...
If the file location is the WindowsApps folder in Program Files, or Windows 10 refuses to open the folder, then it is a UWP App, because Win32 apps are stored in their own folder in Program Files (x86) and 64bit applications are stored in their own folder in Program Files . . . Power to the Developer!
When you're debugging an app, you can send it a suspend event using Visual Studio. Make sure the Debug Location toolbar is being shown, then click the Suspend icon.
Universal Windows Platform (UWP) is a computing platform created by Microsoft and first introduced in Windows 10. The purpose of this platform is to help develop universal apps that run on Windows 10, Windows 10 Mobile, Windows 11, Xbox One, Xbox Series X/S and HoloLens without the need to be rewritten for each.
App close confirmation in UWP. It is a common request from app developers to be able to display a confirmation dialog when their app is being closed. Although this scenario is becoming less and less relevant in days of mobile apps and cloud-based data, it is still useful in specific cases.
A UWP app is suspended shortly after the user minimizes it or switches to another app. This means that the app's threads are stopped and the app is left in memory unless the operating system needs to reclaim resources. When the user switches back to the app, it can be quickly restored to a running state.
But you might choose to call Close if you want to stop the app service regardless of outstanding references to the app service connection. After calling Close in a situation like that, we recommend that you consider the object to be invalid, and not to use it further.
The terminated app will still appear in the task bar. When the user click on it, the app must restore the state that it was in before it was terminated because the user will not be aware that the system closed the app.
You can use the EnteredBackground/LeavingBackground events to distinguish the two scenarios.
Here is a full sample showing this approach:
https://github.com/StefanWickDev/UWP-FullTrust/tree/master/UWP_FullTrust_3
Related blog post:
https://stefanwick.com/2018/04/16/uwp-with-desktop-extension-part-3/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With