zoukankan      html  css  js  c++  java
  • wpf 让正执行的程序暂停几秒钟

    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();//这里就可以调用了
  • 相关阅读:
    python datetime,字符串,时间戳相互转换
    python在linux环境读取access数据库mdb文件
    ruby 随机字符串rand方法避坑
    gin 页面重定向
    go语言 goquery爬虫
    Rails项目防止时序攻击
    Authorization With Pundit
    Rails/ActiveRecord order by Array
    java线程池
    Java安全API
  • 原文地址:https://www.cnblogs.com/dotnetHui/p/7839827.html
Copyright © 2011-2022 走看看