WPF的实时更新

public partial class App : Application
    {
        #region DoEvent
        private static DispatcherOperationCallback exitFrameCallback = new DispatcherOperationCallback(ExitFrame);
        private static Object ExitFrame(Object state)
        {
            DispatcherFrame frame = state as DispatcherFrame;
            // Exit the nested message loop.            
            if (frame != null)
            { frame.Continue = false; }
            return null;
        }
        public static void DoEvents()
        {
            DispatcherFrame nestedFrame = new DispatcherFrame();
            DispatcherOperation exitOperation = Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, exitFrameCallback, nestedFrame);
            Dispatcher.PushFrame(nestedFrame);
            if (exitOperation.Status != DispatcherOperationStatus.Completed)
            {
                exitOperation.Abort();
            }
        }
        #endregion
}

  在使用的过程中,可以在 Application.Current.Dispatcher.Invoke中调用来更新了

posted @ 2024-04-09 15:25  hurui12  阅读(13)  评论(0编辑  收藏  举报