0

I am working in windows 10 app. I am really confused when windows 10 app suspend and resume events are fired. I have below event in App.cs page, however, this event never fires.

private void OnSuspending(object sender, SuspendingEventArgs e)
{
   var deferral = e.SuspendingOperation.GetDeferral();
   //TODO: Save application state and stop any background           
 ApplicationSettingsHelper.SaveSettingsValue(ApplicationSettingsConstants.AppState, (short)AppState.Suspended);
   ApplicationDataSource.saveRecent(Recent);
   deferral.Complete();
}

I have also tried to add onsuspend event in MainPage load event using below code, but this is also never fired.

Application.Current.Suspending += Current_Suspending;

when does the event Onsuspend is fired and what is the difference between the two above method?

Thanks!

Franklin Chen - MSFT
  • 4,845
  • 2
  • 17
  • 28
ARH
  • 1,566
  • 3
  • 25
  • 56
  • Debugging a suspended app isn't a lot of fun. So you have to invoke it yourself. Well hidden btw, right-click the VS toolbar and click "Debug Location". You now get a "Lifecycle events" dropdown, pick "Suspend". – Hans Passant Oct 21 '15 at 12:00

1 Answers1

2

That's because OnSuspended will not raise if you are normal debugging. Please look at answer to this question Suspending event not raising using WinRT

Community
  • 1
  • 1
Festyk
  • 316
  • 1
  • 6