WPF的實時更新

hurui12發表於2024-04-09
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中呼叫來更新了

相關文章