循环执行利用Trmer控件
private System.Timers.Timer IntoTime = new System.Timers.Timer();
private void ShowForm_Load(object sender, System.EventArgs e)
{
int iClockInterval = 0;
iClockInterval = int.Parse(ConfigurationSettings.AppSettings["iClockInterval"].ToString());
int iTimeCount = iClockInterval / 1000 / 60; //转换为分钟显示
Clock.Interval = iClockInterval;
//设置Clock_Elapsed启动状态
IntoTime.Stop();
Show_Form();
//设置Clock_Elapsed启动状态
IntoTime.Start();
}
private void Clock_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//定义间隔时间
int iClockInterval = 0;
if(sender==Clock && IntoTime.Enabled == true)
{
//设置Clock_Elapsed启动状态
IntoTime.Enabled = false;
//设置完全满足执行Show_Form();方法的时间间隔来重新走Clock_Elapsed事件;
Clock.Interval = 10000000;
Show_Form();
//重新设置回约定好的Clock_Elapsed事件循环间隔时间
iClockInterval = int.Parse(ConfigurationSettings.AppSettings["iClockInterval"].ToString());
Clock.Interval = iClockInterval;
//设置Clock_Elapsed启动状态
IntoTime.Enabled = true;
}
}
private System.Timers.Timer IntoTime = new System.Timers.Timer();
private void ShowForm_Load(object sender, System.EventArgs e)
{
int iClockInterval = 0;
iClockInterval = int.Parse(ConfigurationSettings.AppSettings["iClockInterval"].ToString());
int iTimeCount = iClockInterval / 1000 / 60; //转换为分钟显示
Clock.Interval = iClockInterval;
//设置Clock_Elapsed启动状态
IntoTime.Stop();
Show_Form();
//设置Clock_Elapsed启动状态
IntoTime.Start();
}
private void Clock_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//定义间隔时间
int iClockInterval = 0;
if(sender==Clock && IntoTime.Enabled == true)
{
//设置Clock_Elapsed启动状态
IntoTime.Enabled = false;
//设置完全满足执行Show_Form();方法的时间间隔来重新走Clock_Elapsed事件;
Clock.Interval = 10000000;
Show_Form();
//重新设置回约定好的Clock_Elapsed事件循环间隔时间
iClockInterval = int.Parse(ConfigurationSettings.AppSettings["iClockInterval"].ToString());
Clock.Interval = iClockInterval;
//设置Clock_Elapsed启动状态
IntoTime.Enabled = true;
}
}