0

The suspending event doesn't raised whenever I click close button.

private async void Current_Suspending(object sender,SuspendingEventArgs e)
{
    var deferral = e.SuspendingOperation.GetDeferral();
    MessageDialog md = new MessageDialog("do you want to save changes to untitled? ");
    await md.ShowAsync();
    deferral.Complete();
}
Bart
  • 9,925
  • 7
  • 47
  • 64

1 Answers1

1

You can't show MessageDialog in Suspending event - this event is raised as user already has left your app. You have very limited time to do something (like saving state of the app), if time is run out, the OS will terminate the process.

You can't prevent user from leaving your app - this is by design.

If you want to debug your event - take a look at this answer.

Community
  • 1
  • 1
Romasz
  • 29,662
  • 13
  • 79
  • 154
  • Is there any event to show MessageDialog before the application is closed. – rajini raja Dec 06 '15 at 10:31
  • when you open Multiple tabs in Edge browser in windows 10 and click the close button. It shows a contentDialog control with respective message.I want accomplish the similar process. Is there is any way to do that. – rajini raja Dec 06 '15 at 10:35
  • @rajiniraja You can show message dialog once user clicked back button (there are already some answers on SO about this), but you won't be able to show message when user clicked start button or killed your app with 'x'. – Romasz Dec 06 '15 at 10:35
  • @rajiniraja Inside your app you can provide such UI where there will be 'x' button and once user click it will show a message - but still everything happens inside your app. – Romasz Dec 06 '15 at 10:36