您的位置:首页 > 博客中心 > APP开发 >

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

时间:2022-03-13 00:31

      #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

相关推荐

电脑软件

本类排行

今日推荐

热门手游