App.cs 1.37 KB
using OS.Spin.Common;
using System;
using System.Windows;
using System.Windows.Threading;

namespace OS.Spin.View.Utils
{
    public partial class App : Application
    {
        private static DispatcherOperationCallback exitFrameCallback = new DispatcherOperationCallback(ExitFrame);
        public static void DoEvents()
        {
            try
            {
                DispatcherFrame nestedFrame = new DispatcherFrame();
                DispatcherOperation exitOperation = Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, exitFrameCallback, nestedFrame);
                Dispatcher.PushFrame(nestedFrame);
                if (exitOperation.Status !=
                DispatcherOperationStatus.Completed)
                {
                    exitOperation.Abort();
                }
            }
            catch (Exception ex)
            {
                LogisTrac.WriteLog(string.Format("DoEvents:{0}", ex.Message));
            }
        }

        private static Object ExitFrame(Object state)
        {
            try
            {
                DispatcherFrame frame = state as
                    DispatcherFrame;
                frame.Continue = false;
            }
            catch (Exception ex)
            {
                LogisTrac.WriteLog(string.Format("ExitFrame:{0}", ex.Message));
            }
            return null;
        }

    }
}