C# 定时器 Timers.Timer Forms.Timer
1.定义在System.Windows.Forms里
Windows.Forms里面的定时器比较简单,只要把工具箱中的Timer控件拖到窗体上,然后设置一下事件和间隔时间等属性就可以了
//启动定时器
private void button1_Click(object sender, EventArgs e)
{
timer1.Tick += new EventHandler(timer1_Tick);//执行的方法
timer1.Enabled = true;// 获取或设置计时器是否正在运行。 如果计时器当前处于启用状态,则为 true
timer1.Start();//开启
label1.Text = "已开启";
MessageBox.Show("开启成功");
}
void timer1_Tick(object sender, EventArgs e)
{
MessageBox.Show("执行开始");
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Stop();//停止
label1.Text = "已暂停";
MessageBox.Show("暂停成功");
}
3.定义在System.Timers.Timer类里
使用System.Timers.Timer类
System.Timers.Timer t = new System.Timers.Timer(10000);//实例化Timer类,设置间隔时间为10000毫秒;
t.Elapsed += new System.Timers.ElapsedEventHandler(theout);//到达时间的时候执行事件;
t.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
public void theout(object source, System.Timers.ElapsedEventArgs e)
{
MessageBox.Show("执行开始");
}
C# 定时器 Timers.Timer Forms.Timer的更多相关文章
- 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 基于服务 非阻塞异步 多 ...
- Forms.Timer、Timers.Timer、Threading.Timer的研究
.NET Framework里面提供了三种Timer System.Windows.Forms.Timer System.Timers.Timer System.Threading.Timer 一.S ...
- System.Windows.Forms.Timer、System.Timers.Timer、System.Threading.Timer的差别和分别什么时候用
System.Windows.Forms.Timer.System.Timers.Timer.System.Threading.Timer的 区别和用法http://space.itpub.net/1 ...
- 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
一.主要属性.方法和事件 Windows 窗体 Timer 是定期引发事件的组件.该组件是为 Windows 窗体环境设计的. 时间间隔的长度由 Interval 属性定义,其值以毫秒为单位.若启用了 ...
- java定时器的使用(Timer)
1.在应用开发中,经常需要一些周期性的操作,比如每5分钟执行某一操作等. 对于这样的操作最方便.高效的实现方式就是使用java.util.Timer工具类. private java.util.Tim ...
- java定时器的使用(Timer)(转发:https://blog.csdn.net/ecjtuxuan/article/details/2093757)
1.在应用开发中,经常需要一些周期性的操作,比如每5分钟执行某一操作等. 对于这样的操作最方便.高效的实现方式就是使用java.util.Timer工具类. private java.util.Tim ...
- System.Windows.Forms.Timer反编译学习
using System; using System.ComponentModel; using System.Globalization; using System.Runtime; using S ...
随机推荐
- 史上最全的maven的pom.xml文件详解
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- 定位以及z-index
定位 定位用来控制元素的位置 定位的关键字是position,position有4个值,分别是relative,absolute,static,fixed当元素定位以后,元素有4个值可以用,分别是le ...
- DBNEWNAME工具介绍
下面修改数据库的SID和db_name [root@oracle ~]# su - ora11g db11@oracle /home/ora11g$ db11@oracle /home/ora11g ...
- C++ 系列:内存布局
转载自http://www.cnblogs.com/skynet/archive/2011/03/07/1975479.html 为什么需要知道C/C++的内存布局和在哪可以可以找到想要的数据?知道内 ...
- 基于Netty与RabbitMQ的消息服务
Netty作为一个高性能的异步网络开发框架,可以作为各种服务的开发框架. 前段时间的一个项目涉及到硬件设备实时数据的采集,采用Netty作为采集服务的实现框架,同时使用RabbitMQ作为采集服务和各 ...
- tomcat热部署
tomcat默认支持热部署,修改文件会自动加载部署,不需要重启容器 server.xml配置如下所示 autoDeploy=”true” — 自动部署 reloadable=”true” — 自动加载
- 在Asp.Net MVC 中配置 Serilog
Serilog 是一种非常简便记录log 的处理方式,使用Serilog可以生成本地的text文件, 也可以通过 Seq 来在Web界面中查看具体的log内容. 接下来就简单的介绍一下在Asp.Net ...
- sql 语句
INSERT 基本语法:INSERT INTO table_name VALUES(value1,value2,value3,...); 指定列:INSERT INTO table_name(colu ...
- 解决EditText和ScrollView滑动冲突问题
该类需要调用 OnTouchListener接口 黄色部分是需要更改部分,改为自己的edittext@Override public boolean onTouch(View view, Motion ...
- Qt中暂停线程的执行
在线程中定义一个信号量 QMutex pause; 把run()函数中循环执行的部分用信号量pause锁住: void run() { while(1) { pause.lock(); //循环执行的 ...