public class ApplicationClosingService : CloseApplicationWatcherBase, IApplicationClosingService
{
public bool IsClosing { get; private set; }
public event AsyncEventHandler<EventArgs> ApplicationClosingAsync;
public event EventHandler<EventArgs> ApplicationClosingCanceled;
protected override async Task<bool> ClosingAsync()
{
IsClosing = true;
await ApplicationClosingAsync.SafeInvokeAsync(this, EventArgs.Empty);
return await base.ClosingAsync();
}
protected override void ClosingCanceled()
{
IsClosing = false;
ApplicationClosingCanceled?.Invoke(this, EventArgs.Empty);
base.ClosingCanceled();
}
}
ok, this seems to work
in mainviewmodel
```private async Task ApplicationClosingService_ApplicationClosingAsync(object sender, CancelEventArgs e)
{
var response = await messageService.ShowAsync("Sei sicuro di voler chiudere l'applicazione?",
"Chiusura applicazione", MessageButton.YesNo, MessageImage.Question);
if (response == MessageResult.No)
{
e.Cancel = true;
}
}
in the closeService
protected override async Task<bool> ClosingAsync()
{
IsClosing = true;
var eventArgs = new CancelEventArgs();
await ApplicationClosingAsync.SafeInvokeAsync(this, eventArgs);
if (!eventArgs.Cancel)
return await base.ClosingAsync();
return false;
}
```