Hello,
Welcome to our Microsoft Q&A platform!
When the application is closed, the Suspending
event is indeed triggered. If the expected behavior is not achieved when the user closes the application, can you provide a minimum runnable demo to help us test?
At the same time, you can try another solution to the behavior of the user closing the application.
If you want to handle when the user closes the app, UWP can listen for events when the app is closing. Please follow the steps below:
1. modify the **package.appxmanifest (with code mode).**
<Package
...
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="... rescap">
...
<Capabilities>
...
<rescap:Capability Name="confirmAppClose"/>
</Capabilities>
</Package>
2. handle the CloseRequest
event.
SystemNavigationManagerPreview.GetForCurrentView().CloseRequested += (s, e) =>
{
// do something...
};
It should be noted that this function requires that your application has a minimum system version of 15063, and if you need to submit the application to the Microsoft Store
, you need to explain why you use the API when submitting.
Thanks.