예제 #1
0
        /// <summary>
        /// Called by the app when the app is suspending
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnSuspending_Fired(object sender, SuspendingEventArgs e)
        {
            // Setup a ref deferral for everyone to hold. We also need to setup a clean up action to save the setting
            // when the deferral is done.
            RefCountedDeferral refDeferral = new RefCountedDeferral(e.SuspendingOperation.GetDeferral(), () =>
            {
                // We need to flush the settings here just before we complete the deferal. We need to block this function
                // until the settings are flushed.
                using (AutoResetEvent are = new AutoResetEvent(false))
                {
                    Task.Run(async() =>
                    {
                        // Flush out the local settings
                        await SettingsMan.FlushLocalSettings();
                        are.Set();
                    });
                    are.WaitOne();
                }
            });

            // Add a ref to cover anyone down this call stack.
            refDeferral.AddRef();

            // Make the
            OnSuspendingArgs args = new OnSuspendingArgs()
            {
                RefDeferral = refDeferral
            };

            // Fire the event
            m_onSuspending.Raise(this, args);

            // Release our ref to the deferral
            refDeferral.ReleaseRef();
        }
예제 #2
0
        /// <summary>
        /// Called by the app when the app is suspending
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnSuspending_Fired(object sender, SuspendingEventArgs e)
        {
            // Setup a ref deferral for everyone to hold. We also need to setup a clean up action to save the setting
            // when the deferral is done.
            RefCountedDeferral refDeferral = new RefCountedDeferral(e.SuspendingOperation.GetDeferral(), () =>
            {
                // We need to flush the settings here just before we complete the deferal. We need to block this function
                // until the settings are flushed.
                using (AutoResetEvent are = new AutoResetEvent(false))
                {
                    Task.Run(async () =>
                    {
                        // Flush out the local settings
                        await SettingsMan.FlushLocalSettings();
                        are.Set();
                    });
                    are.WaitOne();
                }
            });

            // Add a ref to cover anyone down this call stack.
            refDeferral.AddRef();

            // Make the 
            OnSuspendingArgs args = new OnSuspendingArgs()
            {
                RefDeferral = refDeferral
            };

            // Fire the event
            m_onSuspending.Raise(this, args);

            // Release our ref to the deferral
            refDeferral.ReleaseRef();
        }