System.Windows.Forms.Timer[C#]
来源:互联网 发布:php开源crm统 编辑:程序博客网 时间:2024/05/16 18:59
public class Class1 { static System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer(); static int alarmCounter = 1; static bool exitFlag = false; // This is the method to run when the timer is raised. private static void TimerEventProcessor(Object myObject, EventArgs myEventArgs) { myTimer.Stop(); // Displays a message box asking whether to continue running the timer. if(MessageBox.Show("Continue running?", "Count is: " + alarmCounter, MessageBoxButtons.YesNo) == DialogResult.Yes) { // Restarts the timer and increments the counter. alarmCounter +=1; myTimer.Enabled = true; } else { // Stops the timer. exitFlag = true; } } public static int Main() { /* Adds the event and the event handler for the method that will process the timer event to the timer. */ myTimer.Tick += new EventHandler(TimerEventProcessor); // Sets the timer interval to 5 seconds. myTimer.Interval = 5000; myTimer.Start(); // Runs the timer, and raises the event. while(exitFlag == false) { // Processes all the events in the queue. Application.DoEvents(); } return 0; } }
注意,在定时器处理方法TimerEventProcessor中,先myTimer.Stop()停止定时器,事件处理完后,再重新启动定时器myTimer.Enabled = true。
这样,可以防止多个定时器事件的同时到来。
0 0
- System.Windows.Forms.Timer[C#]
- System.Windows.Forms.Timer和System.Timers.Timer的区别
- System.Windows.Forms.Timer和System.Timers.Timer的区别
- system.times.timer与system.windows.forms.timer的区别
- System.Timers.Timer与System.Windows.Forms.Timer比较
- System.Windows.Forms.Timer和System.Timers.Timer的区别
- System.Windows.Forms.Timer与System.Timers.Timer区别
- System.Timers.Timer与System.Windows.Forms.Timer 区别
- System.Windows.Forms.Timer与System.Timers.Timer的区别
- System.Windows.Forms.Timer与System.Timers.Timer的区别
- System.Windows.Forms.Timer与System.Timers.Timer的区别
- System.Windows.Forms.Timer与System.Timers.Timer的区别 .
- System.Windows.Forms.Timer与System.Timers.Timer的区别
- System.Windows.Forms.Timer定时器的“自毁”
- 3个Timer(System.Threading.Timer,System.Windows.Forms.Timer,System.Timers.Timer)的区别
- System.Windows.Forms.Timer、System.Timers.Timer和System.Threading.Timer区别
- 关于.net中使用System.Windows.Forms.Timer的限制.
- System.Windows.Forms.Timer和System.Timers.Timer的区别 [转]
- 牛顿迭代法实现平方根函数sqrt
- android ListView 几个重要属性
- debug03:“case expressions must be constant expression”报错的破解
- prepareForSegue方法传入对象的问题
- Android高效加载大图、多图解决方案,有效避免程序OOM
- System.Windows.Forms.Timer[C#]
- Unity获取游戏对象详解
- 贵州贵阳商会商务运作合法吗?好做吗?考察必知
- jqMobi基础(2)--快速入门(基本框架构建)
- C#设计一个窗体
- Python 数据结构 之 串 的顺序存储结构
- NYOJ 寻找最大数(三)
- intel的lock prefix
- typedef