https://docs.microsoft.com/en-us/dotnet/api/system.timers.timer?view=netframework-4.7.2

Be aware that .NET includes four classes named Timer, each of which offers different functionality:

  • System.Timers.Timer (this topic): fires an event at regular intervals. The class is intended for use as a server-based or service component in a multithreaded environment; it has no user interface and is not visible at runtime.
  • System.Threading.Timer: executes a single callback method on a thread pool thread at regular intervals. The callback method is defined when the timer is instantiated and cannot be changed. Like the System.Timers.Timer class, this class is intended for use as a server-based or service component in a multithreaded environment; it has no user interface and is not visible at runtime.
  • System.Windows.Forms.Timer (.NET Framework only): a Windows Forms component that fires an event at regular intervals. The component has no user interface and is designed for use in a single-threaded environment.
  • System.Web.UI.Timer (.NET Framework only): an ASP.NET component that performs asynchronous or synchronous web page postbacks at a regular interval.

System.Threading.Timer is a simple, lightweight timer that uses callback methods and is served by thread pool threads. It is not recommended for use with Windows Forms, because its callbacks do not occur on the user interface thread.

System.Threading.Timer是一个简单的轻量级的计时器,通过使用callback 方法工作,并且由线程池上的线程提供服务。并不推荐将此计时器用于winform,因为它的回调方法不在UI线程上。

System.Windows.Forms.Timer is a better choice for use with Windows Forms.

System.Windows.Forms.Timer是用在winform上的更好选择

For server-based timer functionality, you might consider using System.Timers.Timer, which raises events and has additional features.

如果你需要使用基于服务器的计时器功能,你可以考虑使用System.Timers.Timer,它可以触发事件,并且有额外的功能

在winform中使用计时器的时候,会遇到以下问题:

如果你在计时器中刷新窗体,有使用Invoke方法的话,会出现提示,无法访问已释放的对象。

那么可以在窗体的关闭事件中,调用timer的Dispose方法。

最新文章

  1. Android WebView 支持H5的定位Js
  2. 【原】Linux Raid 实验
  3. [转]Ionic – Mobile UI Framework for PhoneGap/Cordova Developers
  4. XSS 探索
  5. innodb内部的并发线程
  6. 【图解ASP.NET MVC运行机制理解-简易版】
  7. Notepad++ 经常使用快捷键 (MEMO)
  8. Docker 搭建 etcd 集群及管理
  9. Postgres的tuple的组装
  10. ES6 语法学习(二)
  11. 基础篇:8.如何定义变量?js变量有什么特点?
  12. Oracle课程档案,第十二天
  13. Symbol Vs String
  14. Caused by: java.lang.IllegalStateException: commit already called
  15. 在property里面设置版本号可灵活引用
  16. GPLT L2-004 这是二叉搜索树吗?
  17. Redis-HA高可用方案Sentinel配置
  18. 如何修改 Ubuntu 的字符集?
  19. 应用程序创建自己的奔溃转储(crash dump)文件
  20. SVN合并时报错:Merge tracking not allowed with missing subtrees; try restoring these items

热门文章

  1. 在TextView中设置DrawableLeft不显示的问题
  2. hdu4045(递推)
  3. 《JAVA多线程编程核心技术》 笔记:第一章
  4. 基于Web和二维码的文件传输服务
  5. Android Download机制详解(一)DocumentUI部分
  6. 初探runtime
  7. 2015-04-14——css3 @media
  8. 删除DOM元素 parent.removeChild(target)
  9. Python高级教程-迭代
  10. 自己定义图片的progressbar