C# System.Windows.Forms.Timer定时器的使用
1、定义Timer
1 public Timer timerForm;
1 private void MainWindow_Load(object sender, EventArgs e) 2 { 3 //pushTime为配置文件中配置的时间,单位分钟 4 timerForm = new Timer() { Interval = Convert.ToInt32(pushTime) * 60 * 1000 }; 5 timerForm.Tick += TimerForm_Tick; 6 //一直执行 7 timerForm.Enabled = true; 8 timerForm.Start(); 9 }
2、TimerForm_Tick方法
1 private void TimerForm_Tick(object sender, EventArgs e) 2 { 3 GetFlowStatus(operCode);//具体的逻辑 4 }
3、在form窗口关闭的时候
1 timerForm.Stop();