c# - OnSuspending event not triggered with UWP Windows 10 -


the onsuspending event not triggered uwp app problem occurs on windows phone running windows 10. works expected when running windows store app on local machine or simulator.

i'm using event save app's settings when app closing, causing major problem windows phone since event not triggered.

as can see, onsuspending event initialized when app starts

public app() {     microsoft.applicationinsights.windowsappinitializer.initializeasync(         microsoft.applicationinsights.windowscollectors.metadata |         microsoft.applicationinsights.windowscollectors.session);     this.initializecomponent();     this.suspending += onsuspending; } 

below onsuspending code should called isn't when running in windows phone 10.

private async void onsuspending(object sender, suspendingeventargs e) {     var deferral = e.suspendingoperation.getdeferral();      //todo: save application state , stop background activity     await locator.mainpageviewmodel.savesettings();      deferral.complete(); } 

any ideas on how can resolve or there potential work-around?

thanks.

update-1:

when terminate app holding flag key , click on cross terminate it, closes app still doesn't trigger onsuspending event, .net ide still runs. when press f5 run app again, triggers onsuspending event. app starts code stops running in ide.

from official app lifecycle documentation:

a note debugging using visual studio: visual studio prevents windows suspending app attached debugger. allow user view visual studio debug ui while app running. when you're debugging app, can send suspend event using visual studio. make sure debug location toolbar being shown, click suspend icon.

that means onsuspending event won't fired while attached visual studio debugger. if want debug it, manually send event selecting respective lifecycle event.

enter image description here


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -