1 System.Windows.Forms.Timer setTimer; //定义一个定时器 2 int flg = 0; //定义一个竖旗 3 private void btnSetTime_Click(object sender, EventArgs e) 4 { 5 setTimer = new System.Windows.Forms.Timer(); 6 int i = Convert.ToInt32(nudSetTime.Value); //界面控件的值,初始化隔5分钟刷新一次,可自定义 7 switch (i) 8 { 9 case 5: 10 setTimer.Interval = 5000; //每隔5秒自动执行一次 11 break; 12 case 10: 13 setTimer.Interval = 10000; //每隔10秒自动执行一次 14 break; 15 case 15: 16 setTimer.Interval = 900000; //每隔15分钟自动执行一次 17 break; 18 } 19 setTimer.Tick += Timer1_Tick; 20 setTimer.Start(); //开启定时器 21 flg = 1; 22 } 23 //加载地图 24 private void Timer1_Tick(object sender, EventArgs e) 25 { 26 gMapLoad(); 27 } 28 //当间隔时间值发生改变时,定时器则关闭 29 private void nudSetTime_ValueChanged(object sender, EventArgs e) 30 { 31 if (flg == 1) 32 { 33 setTimer.Stop(); //关闭定时器 34 flg = 0; 35 } 36 }
时间: 2024-11-02 10:14:27