首页 技术 正文
技术 2022年11月11日
0 收藏 726 点赞 3,261 浏览 1686 个字

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方法。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,564
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905