// This method saves the application state before entering background state. It fires the event OnBackgroundEntering to collect // state data from the current subscriber and saves it to the local storage. public async Task <bool> SaveStateAsync() { if (OnBackgroundEntering == null) { return(false); } try { var suspensionState = new SuspensionState() { SuspensionDate = DateTime.Now }; var target = OnBackgroundEntering?.Target.GetType(); var onBackgroundEnteringArgs = new OnBackgroundEnteringEventArgs(suspensionState, target); OnBackgroundEntering?.Invoke(this, onBackgroundEnteringArgs); await ApplicationData.Current.LocalFolder.SaveAsync(StateFilename, onBackgroundEnteringArgs); return(true); } catch (Exception) { // TODO WTS: Save state can fail in rare conditions, please handle exceptions as appropriate to your scenario. return(false); } }
public async Task SaveStateAsync() { var suspensionState = new SuspensionState() { SuspensionDate = DateTime.Now }; var target = OnBackgroundEntering?.Target.GetType(); var onBackgroundEnteringArgs = new OnBackgroundEnteringEventArgs(suspensionState, target); OnBackgroundEntering?.Invoke(this, onBackgroundEnteringArgs); await ApplicationData.Current.LocalFolder.SaveAsync(StateFilename, onBackgroundEnteringArgs); }