Hello,
When you close the app, the lifecycle events of Window will be triggered. And you could update your local database in the Stopped
method. (Or you can do the operation in the Backgrounding
method)
For example:
// in the App class
protected override Window CreateWindow(IActivationState? activationState)
{
Window window = base.CreateWindow(activationState);
window.Backgrounding += Window_Backgrounding;
window.Stopped += Window_Stopped;
return window;
}
private void Window_Stopped(object? sender, EventArgs e)
{
Console.WriteLine("Window_Stopped");
}
private void Window_Backgrounding(object? sender, BackgroundingEventArgs e)
{
Console.WriteLine("Window_Backgrounding");
}
For more details, please see App lifecycle - .NET MAUI | Microsoft Learn
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.