使用System.Timers.Timer类
来源:互联网 发布:淘宝任务发布平台 编辑:程序博客网 时间:2024/06/05 16:10
使用System.Timers.Timer类 :
System.Timers.Timer t = new System.Timers.Timer(10000);//实例化Timer类,设置间隔时间为10000毫秒;
t.Elapsed += new System.Timers.ElapsedEventHandler(theout); //到达时间的时候执行事件;theout为要执行的函数
t.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
System.Timers.Timer t = new System.Timers.Timer(10000);//实例化Timer类,设置间隔时间为10000毫秒;
t.Elapsed += new System.Timers.ElapsedEventHandler(theout); //到达时间的时候执行事件;theout为要执行的函数
t.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
注意事项:
1 在有多个timer时,类似于多个线程;多线程下如果同时操作一个文件为发生资源争抢的情况,这个时候需要考虑对资源加锁,例如创建一个lock文件,当资源被一个线程访问时,线程先判断该文件是否存在,如果存在就等待,如果不存在就创建该文件执行数据操作,完成之后删除此lock文件;下个线程访问同上
2 单个计时器在执行时,可能会存在这次任务未执行完,下个任务又开始执行的情况;这个时候就需要在计时器到达执行时间时,在执行函数里面暂停此计时器的计时,等次函数执行完毕,再开启此计时器;
0 0
- 使用System.Timers.Timer类
- System.Timers.Timer的使用
- Timer控件使用(System.Timers.Timer)
- Timer控件使用(System.Timers.Timer)
- 在C#中使用System.Timers.Timer
- 在C#中使用System.Timers.Timer
- 在C#中使用System.Timers.Timer
- 使用System.Timers.Timer实现协同
- C#中System.Timers.Timer的使用
- 定时器 System.Timers.Timer的使用
- System.Timers.Timer定时器的使用
- System.Timers.Timer
- System.Timers.Timer用法
- 关于System.Timers.Timer
- System.Timers.Timer
- SYstem.Timers.Timer用法
- System.Timers.Timer重置
- C#使用System.Timers.Timer类实现一个Button锁定功能(windows form)
- 第十一章:表单标签——深入浅出学Spring Web MVC
- Fedora 安装后需要做的第一件事
- 移除子试图的方式
- 1232 - Coin Change (II)
- 利用Powershell快速导出域控所有用户Hash
- 使用System.Timers.Timer类
- phpcms 任意页面调用自定义字段多图片
- 访问系统相册或调用摄像头
- 归并排序
- OpenCV 轮廓检测
- [NOIP 2009]最优贸易 Spfa
- 【Linux学习】epoll详解
- SpringMVC 使用JSR-303进行校验 @Valid
- iOS Parse教程——如何使用Parse在iOS应用创建后台服务