public static class DispatcherHelper
    {
        [SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
        public static void DoEvents()
        {
            DispatcherFrame frame = new DispatcherFrame();
            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrames), frame);
            try { Dispatcher.PushFrame(frame); }
            catch (InvalidOperationException) { }
        }
        private static object ExitFrames(object frame)
        {
            ((DispatcherFrame)frame).Continue = false;
            return null;
        }
    } 
在需要暂停的地方调用即可:DispatcherHelper.DoEvents();
如下面的示例:
    //让它暂停3秒种
    var t = DateTime.Now.AddMilliseconds(3000);
    while (DateTime.Now < t)
         DispatcherHelper.DoEvents();//这里就可以调用了

相关文章:

  • 2021-12-12
  • 2022-12-23
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
  • 2021-08-22
  • 2021-12-12
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-29
  • 2021-08-10
  • 2022-12-23
  • 2021-10-18
  • 2021-12-12
  • 2022-12-23
相关资源
相似解决方案