private async void ExtendedExecutionSessionRevoked(object sender, ExtendedExecutionRevokedEventArgs args)
        {
            //If session is revoked, make the OnSuspending event handler stop or the application will be terminated
            if (cancellationTokenSource != null)
            {
                cancellationTokenSource.Cancel();
            }

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                switch (args.Reason)
                {
                case ExtendedExecutionRevokedReason.Resumed:
                    // A resumed app has returned to the foreground
                    rootPage.NotifyUser("Extended execution revoked due to returning to foreground.", NotifyType.StatusMessage);
                    break;

                case ExtendedExecutionRevokedReason.SystemPolicy:
                    //An app can be in the foreground or background when a revocation due to system policy occurs
                    MainPage.DisplayToast("Extended execution revoked due to system policy.");
                    rootPage.NotifyUser("Extended execution revoked due to system policy.", NotifyType.StatusMessage);
                    break;
                }

                suspendDeferral?.Complete();
                suspendDeferral = null;
            });
        }
        private async void OnSuspending(object sender, SuspendingEventArgs args)
        {
            suspendDeferral = args.SuspendingOperation.GetDeferral();

            rootPage.NotifyUser("", NotifyType.StatusMessage);

            using (var session = new ExtendedExecutionSession())
            {
                session.Reason      = ExtendedExecutionReason.SavingData;
                session.Description = "Pretending to save data to slow storage.";
                session.Revoked    += ExtendedExecutionSessionRevoked;

                ExtendedExecutionResult result = await session.RequestExtensionAsync();

                switch (result)
                {
                case ExtendedExecutionResult.Allowed:
                    // We can perform a longer save operation (e.g., upload to the cloud).
                    try
                    {
                        MainPage.DisplayToast("Performing a long save operation.");
                        cancellationTokenSource = new CancellationTokenSource();
                        await Task.Delay(TimeSpan.FromSeconds(10), cancellationTokenSource.Token);

                        MainPage.DisplayToast("Still saving.");
                        await Task.Delay(TimeSpan.FromSeconds(10), cancellationTokenSource.Token);

                        MainPage.DisplayToast("Long save complete.");
                    }
                    catch (TaskCanceledException) { }
                    break;

                default:
                case ExtendedExecutionResult.Denied:
                    // We must perform a fast save operation.
                    MainPage.DisplayToast("Performing a fast save operation.");
                    await Task.Delay(TimeSpan.FromSeconds(1));

                    MainPage.DisplayToast("Fast save complete.");
                    break;
                }

                session.Revoked -= ExtendedExecutionSessionRevoked;
            }

            suspendDeferral?.Complete();
            suspendDeferral = null;
        }
        /// <summary>
        /// Release a ref to the deferral. If this is the last ref the deferral will be complete.
        /// </summary>
        public void ReleaseRef()
        {
            lock (this)
            {
                _refCount--;

                if (_refCount != 0)
                {
                    return;
                }
                // If we have a cleanup action fire it now.
                _cleanUpAction?.Invoke();

                // Note the deferral can be null, this will happen when we update while
                // the app is updating.
                _deferral?.Complete();

                _suspendingDeferral?.Complete();
            }
        }
        private void ExtendedExecutionSessionRevoked(object sender, ExtendedExecutionRevokedEventArgs args)
        {
            //If session is revoked, make the OnSuspending event handler stop or the application will be terminated
            //if (cancellationTokenSource != null) { cancellationTokenSource.Cancel(); }

            switch (args.Reason)
            {
            case ExtendedExecutionRevokedReason.Resumed:
                // A resumed app has returned to the foreground
                _logHelper.Log(LogLevel.Error, $"Extended execution revoked due to returning to foreground.");
                break;

            case ExtendedExecutionRevokedReason.SystemPolicy:
                //An app can be in the foreground or background when a revocation due to system policy occurs
                _logHelper.Log(LogLevel.Error, $"Extended execution revoked due to system policy.");
                break;
            }

            suspendDeferral?.Complete();
            suspendDeferral = null;
        }
        async void OnApplicationSuspending(object sender, SuspendingEventArgs args)
        {
            // Save application settings
            appSettings.Save();

            // Save current bitmap
            SuspendingDeferral deferral = args.SuspendingOperation.GetDeferral();

            try
            {
                StorageFolder localFolder = ApplicationData.Current.LocalFolder;
                StorageFile   storageFile = await localFolder.CreateFileAsync("FingerPaint.png",
                                                                              CreationCollisionOption.ReplaceExisting);
                await SaveBitmapToFile(storageFile);
            }
            catch
            {
                // Ignore any errors
            }

            deferral.Complete();
        }
Exemple #6
0
        private async void OnSuspending(object sender, SuspendingEventArgs e)
        {
            SuspendingDeferral deferral = e.SuspendingOperation.GetDeferral();
            var newSession = new ExtendedExecutionSession
            {
                Reason = ExtendedExecutionReason.SavingData
            };

            newSession.Revoked += NewSession_Revoked;

            ExtendedExecutionResult result = await newSession.RequestExtensionAsync();

            if (result == ExtendedExecutionResult.Allowed)
            {
                await SharedState.LogAsync("Scannit: SUSPENDING!");

                await SharedState.SetAsync(SharedState.IsApplicationInForeground, false);

                newSession.Revoked -= NewSession_Revoked;
                newSession.Dispose();
                newSession = null;
            }
            deferral.Complete();
        }
Exemple #7
0
        private void CoreApplication_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
        {
            SuspendingDeferral deferral = e.SuspendingOperation.GetDeferral();

            deferral.Complete();
        }
        private void OnSuspending(object sender, SuspendingEventArgs e)
        {
            SuspendingDeferral deferral = e.SuspendingOperation.GetDeferral();

            deferral.Complete();
        }
 async void OnSuspending(object sender, SuspendingEventArgs args)
 {
     SuspendingDeferral deferral = args.SuspendingOperation.GetDeferral();
     await SuspensionManager.SaveAsync();
     deferral.Complete();
 }
        private async void App_SuspendingAsync(object sender, SuspendingEventArgs args)
        {
            try
            {
                suspendDeferral = args.SuspendingOperation.GetDeferral();

                //DateTimeOffset deadline = args.SuspendingOperation.Deadline;
                _logHelper.Log(LogLevel.Trace, $"Entered App_SuspendingAsync.");

                using (var session = new ExtendedExecutionSession())
                {
                    session.Reason      = ExtendedExecutionReason.SavingData;
                    session.Description = "Saving application state.";
                    session.Revoked    += ExtendedExecutionSessionRevoked;

                    ExtendedExecutionResult result = await session.RequestExtensionAsync();

                    switch (result)
                    {
                    case ExtendedExecutionResult.Allowed:
                        // We can perform a longer save operation (e.g., upload to the cloud).
                        try
                        {
                            StorageFolder localFolder = ApplicationData.Current.LocalFolder;
                            await localFolder.SaveAsync(PropertiesDictionaryFileName, Properties);

                            await MainViewModel.Instance.UpdateDownloadedBulletinsAsync();
                        }
                        catch (TaskCanceledException te)
                        {
                            _logHelper.Log(LogLevel.Trace, $"Extended Execution Error. {te.Message}");
                        }
                        break;

                    default:
                    case ExtendedExecutionResult.Denied:
                        // We must perform a fast save operation.
                        _logHelper.Log(LogLevel.Trace, $"Extended Execution denied");
                        //MainPage.DisplayToast("Performing a fast save operation.");
                        //await Task.Delay(TimeSpan.FromSeconds(1));
                        //MainPage.DisplayToast("Fast save complete.");
                        break;
                    }

                    session.Revoked -= ExtendedExecutionSessionRevoked;
                }

                //StorageFolder localFolder = ApplicationData.Current.LocalFolder;
                //await localFolder.SaveAsync(PropertiesDictionaryFileName, Properties);

                //await Singleton<SuspendAndResumeService>.Instance.SaveStateAsync();

                //await MainViewModel.Instance.UpdateDownloadedBulletinsAsync();
            }
            catch (Exception e)
            {
                _logHelper.Log(LogLevel.Error, $"App_SuspendingAsync exception. {e.Message}");
            }
            finally
            {
                suspendDeferral?.Complete();
                suspendDeferral = null;
            }
        }