winform 使用Thread.Sleep界面卡死 使用 Application.DoEvents 方法防止UI假死

      #region 毫秒延时 界面不会卡死
        public static void Delay(int mm)
        {
            DateTime current = DateTime.Now;
            while (current.AddMilliseconds(mm) > DateTime.Now)
            {
                Application.DoEvents();
            }
            return;
        }
        #endregion

Application.DoEvents()的作用:处理所有的当前在消息队列中的Windows消息
其实doEnvents很简单,就是暂停一下当前模块Code,好让你程序可以响应其它事件、消息……
响应完其它事之后又回去继续执行刚才的Code (允许窗体在忙时响应 UI 输入)

避免使用 Thread.Sleep

此随笔或为自己所写、或为转载于网络。仅用于个人收集及备忘。

原文地址:https://www.cnblogs.com/shy1766IT/p/14956130.html