System.Windows.Forms.Timer、System.Timers.Timer、System.Threading.Timer的差别和分别什么时候用
System.Windows.Forms.Timer、System.Timers.Timer、System.Threading.Timer的 区别和用法
http://space.itpub.net/12639172/viewspace-571197
http://msdn.microsoft.com/en-us/magazine/cc164015.aspx
==================================================
System.Windows.Forms.Timer执行的时候,如果你在过程中间加一个sleep整个的界面就死掉了,
但是另外两个没有这个情况,System.Timers.Timer、System.Threading.Timer!
System.Timers.Timer、System.Threading.Timer这两个平时用的时候没有发现太大的区别,定时的精度都差不多。
一般我个人用的话,还是用的System.Threading.Timer比较多,用编程的方法比较好用!
System.Windows.Forms.Timer是基于UI的
System.Timers.Timer是基于服务
System.Threading.Timer是基于线程
除了Timer只能用于界面,其他的事在没看出区别
System.Windows.Forms.Timer 还有 wpf那个timer 是单线程的 单次运行时间过长会影响下次触发 精度差
System.Threading.Timer 都是多线程的 单次运行时间过长不会影响下次触发
精度高
System.Threading.Timer 是一个简单的轻量计时器,它使用回调方法并由线程池线程提供服务。不建议将其用于 Windows 窗体,因为其回调不在用户界面线程上进行。System.Windows.Forms.Timer 是用于 Windows 窗体的更佳选择。要获取基于服务器的计时器功能,可以考虑使用 System.Timers.Timer,它可以引发事件并具有其他功能。
在《CLR Via C#》中讲多线程时有提到这3个计时器,但作者说System.Timers.Timer是对System.Threading.Timer的报装,不推荐使用,但是在我的WEB项目中的Application_Start中我还是使用的这个而不是Threading.Timer,因为使用Threading.Timer时只执行了一次就不在执行了。
对于计时器在B/S结构中的使用就复杂一些,一般我们把计时器放在Application_OnStart中,这样全局维护一个计时器,可以进行定期备份数据库,定期维护用户等操作,而且方法写作静态的,以免被垃圾回收。而不建议在一般的aspx页面中使用,因为服务器端的定时器对用户这样意义不大,完全可以使用JS代替。而且这个页面的每个请求都可能引入一个新的定时器,导致系统崩溃。另外,定时器是ASP.NET进程,IIS有关,所以对用重要的执行任务,还是建议写成服务或独立程序放在服务器上执行好了。
http://blog.itpub.net/12639172/viewspace-571197
System.Windows.Forms.Timer、System.Timers.Timer、System.Threading.Timer的差别和分别什么时候用的更多相关文章
- System.Windows.Forms.Control : Component, IOleControl, IOleObject, IOleInPlaceObject, IOleInPlaceActiveObject....
#region 程序集 System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ...
- System.Windows.Forms.ListView : Control
#region 程序集 System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ...
- System.Windows.Forms.Help
在开发过程中,基本都需要实现帮助功能,而一般帮助功能就是打开一个帮助文档,System.Windows.Forms提供了Help类用于打开帮助文档,挺方便的. Help类提供的方法如下: Name ...
- System.Windows.Forms.Timer与System.Timers.Timer的区别(zz)
.NET Framework里面提供了三种Timer: System.Windows.Forms.Timer System.Timers.Timer System.Threading.Timer VS ...
- System.Windows.Forms.Timer、System.Timers.Timer、System.Threading.Timer的 区别和用法
System.Windows.Forms.Timer执行的时候,如果你在过程中间加一个sleep整个的界面就死掉了,但是另外两个没有这个情况,System.Timers.Timer.System.Th ...
- 简述System.Windows.Forms.Timer 与System.Timers.Timer用法区别
System.Windows.Forms.Timer 基于窗体应用程序 阻塞同步 单线程 timer中处理时间较长则导致定时误差极大. System.Timers.Timer 基于服务 非阻塞异步 多 ...
- System.Windows.Forms.Timer反编译学习
using System; using System.ComponentModel; using System.Globalization; using System.Runtime; using S ...
- System.Windows.Forms.Timer
一.主要属性.方法和事件 Windows 窗体 Timer 是定期引发事件的组件.该组件是为 Windows 窗体环境设计的. 时间间隔的长度由 Interval 属性定义,其值以毫秒为单位.若启用了 ...
- .net chart(图表)控件的使用-System.Windows.Forms.DataVisualization.dll
这个案例指在介绍微软这套免费又功能强大的图表控件Microsoft Chart Controls for Microsoft .NET Framework 3.5,通过它,可让您的项目及报表,轻松套用 ...
随机推荐
- MySQL介绍及安装环境配置
MySQL介绍及安装环境配置 MySQL是一种关系数据库管理系统,是一种开源软件.由瑞典MySQL AB公司开发,2008年1月16号被Sun公司收购.2009年,SUN又被Oracle收购.MySQ ...
- std::map 的swap错用
map<int, shared_ptr<int>>map_test; shared_ptr<); map_test[] = tmp_1; shared_ptr<); ...
- git生成公钥public key并添加SSH key。git乌龟gerrit下推送git【server sent :publickey】
一.key 码云链接:http://git.mydoc.io/?t=180845#text_180845 博客链接: 方式一:https://blog.csdn.net/xb12369/article ...
- Mybatis XML配置(转载)
原文地址:https://www.w3cschool.cn/mybatis/f4uw1ilx.html Mapper XML 文件 MyBatis 的真正强大在于它的映射语句,也是它的魔力所在.由于它 ...
- DNS如何工作
上一篇文章(什么是DNS)中,我们解释了 DNS 所涉及到的一些术语,接下来我们来看看 DNS 这个系统是如何工作的? 从高层次上看,这个系统非常简单,但是当你关注细节时,它又非常复杂.总的来说,它是 ...
- 【树形dp 思维题】HHHOJ#483. NOIP司马懿
要注意利用一些题目的特殊条件吧. 题目大意 有一颗$n$个点带点权$a_i$的树,$q$次询问树上是否存在长度为$l$的路径. $n,q,l\le 10^5,0 \le a_i \le 2$ 题目分析 ...
- Mac常用设置备忘
1.显示隐藏文件 1>命令行方式 显示:defaults write com.apple.finder AppleShowAllFiles -bool true 隐藏:defaults writ ...
- PLS做soft particle
这个pixel local storage frame fetch 可以一个pass做出soft particle/deferred lighting/soft edge water programb ...
- Java-收邮件
import java.util.Properties; import javax.mail.Folder; import javax.mail.Message; import javax.mail. ...
- select * from a,b探讨
select * from a,b探讨 今天看同事代码里使用了select * from a,b where a.id=b.id,而我平时都是使用select * from a inner join ...