C# 控制台定时器
C# 定时器
关于C#中timer类 在C#里关于定时器类就有3个
1.定义在System.Windows.Forms里
2.定义在System.Threading.Timer类里
3.定义在System.Timers.Timer类里
System.Windows.Forms.Timer是应用于WinForm中的,他是通过Windows消息机制实现的,类似于VB或Delphi中的Timer控件,内部使用API SetTimer实现的。他的主要缺点是计时不精确,而且必须有消息循环,Console Application(控制台应用程式)无法使用。
System.Timers.Timer和System.Threading.Timer很类似,他们是通过.NET Thread Pool实现的,轻量,计时精确,对应用程式、消息没有特别的需要。System.Timers.Timer还能够应用于WinForm,完全取代上面的Timer控件。他们的缺点是不支持直接的拖放,需要手工编码。关于C#中timer类 在C#里关于定时器类就有3个
1.定义在System.Windows.Forms里
2.定义在System.Threading.Timer类里
3.定义在System.Timers.Timer类里
System.Windows.Forms.Timer是应用于WinForm中的,他是通过Windows消息机制实现的,类似于VB或Delphi中的Timer控件,内部使用API SetTimer实现的。他的主要缺点是计时不精确,而且必须有消息循环,Console Application(控制台应用程式)无法使用。
System.Timers.Timer和System.Threading.Timer很类似,他们是通过.NET Thread Pool实现的,轻量,计时精确,对应用程式、消息没有特别的需要。System.Timers.Timer还能够应用于WinForm,完全取代上面的Timer控件。他们的缺点是不支持直接的拖放,需要手工编码。
private void Load()
{
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(theout); //到达时间的时候执行事件;
// 设置引发时间的时间间隔 此处设置为1秒(1000毫秒)
aTimer.Interval = 100000;
aTimer.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
aTimer.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件;
}
public void theout(object source, System.Timers.ElapsedEventArgs e)
{
ArrayList AutoTask = new ArrayList();
AutoTask.Add("8:30:00");
AutoTask.Add("9:30:00");
AutoTask.Add("10:30:00");
AutoTask.Add("11:34:15"); for (int n = 0; n < 4; n++)
{
if (DateTime.Now.ToLongTimeString().Equals(AutoTask[n]))
{
MessageBox.Show("现在时间是" + AutoTask[n]);
}
}
}
最新文章
- linux命令汇总
- C#中Object和Json之间的转换
- Java多线程理解
- C#算法之向一个集合中插入随机不重复的100个数
- JAVA jdbc(数据库连接池)学习笔记(一)
- RAD XE10 Seattle
- CodeForces 689D	Friends and Subsequences (RMQ+二分)
- java操作xml方式比较与详解(DOM、SAX、JDOM、DOM4J)
- dataset数据来源方式两种,页面展示
- Net 4.5 WebSocket 在 Windows 7, Windows 8 and Server 2012上的比较
- Node.js 调存储过程
- Mad Lids游戏 华氏与摄氏温度转换
- mac10.12.6系统配置clion编写CMakeLists文件运行opencv3
- C语言基础:分支语句和常见运算符 分类: iOS学习 c语言基础 2015-06-10 21:44 13人阅读 评论(0) 收藏
- GridView Postback后出错Operation is not valid due to the current state of the object.
- Spring Cloud Summary
- CentOS7系统上部署.net core程序
- 20145328 《Java程序设计》第10周学习总结
- filter入门
- BZOJ4602:[SDOI2016]齿轮(并查集)
热门文章
- prototype、__proto__、constructor
- 【louguP2234】[HNOI2002]营业额统计(链表)
- 【BigData】Java基础_类和对象的基本使用
- 安装-consul服务发现集群
- [C++基础] 变量、关键字、运算符、位操作篇
- 正则表达式之re模块
- [POC]微软3389远程漏洞CVE-2019-0708批量检测工具
- AntDesign vue学习笔记(三)嵌套路由使用
- 使用DbVisualizer 10.0.20 查询ES中的索引时需要注意的事项
- InstantiationAwareBeanPostProcessor 分析