c# 使用定时器Timer
来源:互联网 发布:单农为什么淘宝没有 编辑:程序博客网 时间:2024/06/04 17:59
定时器使用的程序。开始---》不断输入aaa 可以停止 继续。
引用:using System.Timers; //、、、、、、、、、、、、、、 public partial class Form1 : Form { public Form1() { InitializeComponent(); this.Load += Form1_Load; } //新建定时器。要用System.Timers.Timer。 //不要用forms.Timer的定时器。这个不精准 System.Timers.Timer myTimer; void Form1_Load(object sender, EventArgs e) { myTimer =new System.Timers.Timer(2000);//定时周期2秒 myTimer.Elapsed += myTimer_Elapsed;//到2秒了做的事件 myTimer.AutoReset = true; //是否不断重复定时器操作 } void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { richTextBox1.Text = richTextBox1.Text + "\n" + "aaa"; } //开始按钮 private void button1_Click(object sender, EventArgs e) { myTimer.Enabled = true; //定时器开始用 //如果不写下面这句会有一个异常。 //异常:线程间操作无效: 从不是创建控件"richtextbox"的线程访问它 //但这不是最好的方法。如果只有一个进程调用richtextbox而已。就可以用下面这句 //如果有多个线程调用richtextbox等控件。就要用委托。具体百度 //一篇参考博客http://www.cnblogs.com/zyh-nhy/archive/2008/01/28/1056194.html Control.CheckForIllegalCrossThreadCalls = false; } private void button2_Click(object sender, EventArgs e) { if (myTimer.Enabled) { myTimer.Enabled = false; //定时器停止 button2.Text = "continue"; } else { myTimer.Enabled = true; button2.Text = "pause"; } } private void button3_Click(object sender, EventArgs e) { myTimer.Close(); //释放Timer占用的资源 myTimer.Dispose(); richTextBox1.Text = richTextBox1.Text + "\n" + "over"; } }
0 0
- c# 使用定时器Timer
- c# 使用定时器Timer
- c# 使用定时器Timer
- Unity3d C# Timer定时器的使用
- C#中定时器timer的使用
- C# Timer 定时器应用
- c#控件-timer,定时器
- C#定时器(Timer)
- C# 使用定时任务 之 谈谈定时器(Timer)的使用
- 使用Timer实现定时器
- Delphi-Timer定时器使用
- timer 定时器的使用
- flex Timer定时器使用
- Timer定时器使用
- LDD3 Timer定时器使用
- linux 定时器timer使用
- Timer定时器的使用
- preloader定时器timer使用
- MP4-2
- 升级ubuntu中的gcc和g++版本
- 《Linux内核设计与实现》--系统调用
- jsp中使用c:import 传递中文参数乱码
- #278 – 允许Image只能变小或者只能变大(Allow an Image to Get Bigger, But Not Smaller (or Vice Versa))
- c# 使用定时器Timer
- 修改UIAlertAction 的文字颜色
- mysql数据库delete数据时不支持表别名
- Linux题目(二)
- TensorFlow教程06:MNIST的CNN实现——源码和运行结果
- 雅虎团队经验:网站页面性能优化的 34条(二)
- 设计模式 ( 十八 ) 策略模式Strategy(对象行为型)
- 解决:Unable to connect to repository https://dl-ssl.google.com/android/eclipse/site.xml
- 无限级CSS树形菜单 Ver2.0