Display “Wait” screen in WPF

前端 未结 4 1127
粉色の甜心
粉色の甜心 2020-12-13 11:26

I am trying to display a please wait dialog for a long running operation. The problem is since this is single threaded even though I tell the WaitScreen to display it never

4条回答
  •  心在旅途
    2020-12-13 12:15

    I found a way! Thanks to this thread.

    public static void ForceUIToUpdate()
    {
      DispatcherFrame frame = new DispatcherFrame();
    
      Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Render, new DispatcherOperationCallback(delegate(object parameter)
      {
        frame.Continue = false;
        return null;
      }), null);
    
      Dispatcher.PushFrame(frame);
    }
    

    That function needs to be called right before the long running operation. That will then Force the UI thread to update.

提交回复
热议问题