cs开发中,有时候界面用线程还是会卡,因为要invoke实时更新窗口,从db读取数据。
用backgroundworker效果不理想,用线程也不理想。
加上这个效果好好多
System.Windows.Forsm.Application.DoEvents();

msdn:
当运行窗体时,会创建新窗体,然后窗体等待处理各种事件,而窗体每次处理事件的时候,都会处理完与
该事件关联的所有代码,才会去处理其它事件。这时其它事件将会在队列中等待。所以在处理事件的时候,程序并不进行响应,当然也不会进行窗口重绘。
但是使用System.Windows.Froms.Application.DoEvents()会使窗口处理其他事件,使窗体能够重绘。

瞟了下源码
Application.cs 源码地址 .net referencesource 1022行
//DotNet48ZDP2/Source/ndp/fx/src/winforms/Managed/System/Windows/Applications.cs

//就是处理消息队列中所有的消息
//Process all windows messages currently in the message queue
public static void DoEvents()
{ThreadContext.FromCurrent().RunMessagelook(NativeMethods.MSOCM.msoloopDoEvents,null);
}//按给出的理由来开始消息循环处理
//starts a message loop for the given readson
interval void RunMessageLoop(int reason,ApplicationContext context)
{//ensure the we attempt to apply theming before doing anything//that might create a window IntPtr userCookie = IntPtr.Zero;//看是否要处理主题风格if(userVisualStyles){userCookie = UnsafeNativeMethods.ThemingScope.Activate();}try{//会循环处理消息 直到停止 while(continueLoop){ ... }//DispatchMessageA 或DispatchMessageW 调用win32apiRunMessageLoopInner(reason,context);}finally{UnsafeNativeMethods.ThemingScopr.Deactivate(userCookie);}
}

C# System.Windows.Forms.Application.DoEvents()相关推荐

  1. System.IO.Directory.GetCurrentDirectory与System.Windows.Forms.Application.StartupPath的用法

    .Net Framework中System.IO.Directory.GetCurrentDirectory()方法用于获得应用程序当前工作目录.如果使用此方法获得应用程序所在的目录,应该注意:Sys ...

  2. Create C++ Windows Forms Application in Visual Studio 2017

    Background: From Windows Forms Application in Visual C++ ???!!!!: "MS removed the WinForms C++/ ...

  3. System.Windows.Forms.ListView

    呈现一个 Windows 列表视图控件,并且能够以四种不同的视图中的任何一种来显示一个子项集合. 命名空间:System.Windows.Forms 汇编集:System.Windows.Forms( ...

  4. c#+AE开发中,System.Windows.Forms.AxHost.InvalidActiveXStateException 在 ESRI.ArcGIS.AxControls.dll 中发生

    问题描述图 //目标框架由3.5改为4.5后会出现无法启动的错误,System.Windows.Forms.AxHost+InvalidActiveXStateException"的异常, ...

  5. 使用.net 6.0框架的WPF应用如何引用System.Windows.Forms这个dll

    在.net 6.0的WPF应用中,想使用OpenFileDialog 这个类或者FolderBrowserDialog这个类,是无法找到System.Windows.Forms这个dll引用的,即使从 ...

  6. System.Windows.Forms.Timer在线程中的注意事项

    在WinForm中使用System.Windows.Forms.Timer对象,如果是在单线程中使用,则直接设置该对象的Enabled属性值即可启动计时器,但如果是在多线程窗体中在多线程引发的事件中调 ...

  7. System.Windows.Forms.ListView : Control

    #region 程序集 System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ...

  8. System.Timers.Timer与System.Windows.Forms.Timer 区别

    根据msdn解释:System.Threading.Timer 是一个简单的轻量计时器,它使用回调方法并由线程池线程提供服务. 不建议将其用于 Windows 窗体,因为其回调不在用户界面线程上进行. ...

  9. C# WinForm编程之System.Windows.Forms.DataGridViewRow.DataBoundItem Property

    Namespace: System.Windows.Forms Assembly: System.Windows.Forms.dll 获取用于填充行的数据绑定对象. 下面的代码示例演示如何使用 Dat ...

最新文章

  1. VC字体安装相关方法总结
  2. Flex 学习笔记 动态设置itemRenderer
  3. 【2016北京集训测试赛】river
  4. 华月互网获得2012全国十大IDC服务商
  5. Cannot resolve field [product], input field list:[user, EXPR$0]
  6. 构造函数的原型和原型链
  7. 设计模式:策略模式(C++)【诸葛亮的锦囊妙计】
  8. python面向对象变成(1):类的基本概念
  9. Region使用全解
  10. Silverlight 功能其全的PDF 控件
  11. 安卓版LightBlue 低功耗蓝牙BLE设备调试
  12. Hbase数据库设计
  13. 系统规划与管理师历年论文
  14. 如何去到Jquery官网下载Jquery
  15. WordPress 使用 CDN 后获取访客真实 IP
  16. 通俗易懂的csrf漏洞(token为什么能放cookie)
  17. 使用R语言进行协整关系检验
  18. Field ‘gmt_create‘ doesn‘t have a default value; nested exception is java.sql.SQLException: Field ‘g
  19. 太给力了!40000字整理了机器学习面试200题!
  20. 【python】python爬虫requests库详解

热门文章

  1. 移动终端播放器的探索历程
  2. Conda:1秒钟修改虚拟环境名称
  3. chisel(Rocket Chip)中如何参数化芯片系统
  4. 数字历史地理教室教育装备设备配套清单
  5. python相比于excel的优势_Python处理excel的优点
  6. jquery遍历多个li_jQuery使用each遍历循环的方法
  7. cinder手动安装
  8. 指针空值——nullptr
  9. linux 删除文件第一行的方法
  10. CIFAR-10数据集(介绍、下载读取、可视化显示、另存为图片)