private void OnSuspending(object sender, SuspendingEventArgs args) { // Save app state asynchronously after requesting a deferral. Holding a deferral // indicates that the application is busy performing suspending operations. Be // aware that a deferral may not be held indefinitely; after about five seconds, // the app will be forced to exit. var deferral = args.SuspendingOperation.GetDeferral(); Task.Run(() => { deviceResources.Trim(); if (null != main) { main.SaveAppState(); } // // TODO: Insert code here to save your app state. // deferral.Complete(); }); }