timer两分钟执行一次,执行了以后界面就不能点了,我想停止timer都停不了,怎么办,大侠们给个具体代码吧
System.Timers.Timer timer1 = new System.Timers.Timer();
//开始停止
private void btnManage_Click(object sender, EventArgs e)
{
btnManage.Text = btnManage.Text == "开始" ? "停止" : "开始";
this.timer1.SynchronizingObject = this;
this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(timer1_Elapsed);
this.timer1.Interval = 20000;
this.timer1.Enabled = !this.timer1.Enabled;
GC.KeepAlive(timer1);
}
//事件
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (flag)
{
flag = false;
if (!Products.IndexNormalData())//创建普通产品索引
Application.Exit();
if (!Products.IndexVipInfoData())//创建VIP产品索引
Application.Exit();
flag = true;
}
}
System.Timers.Timer timer1 = new System.Timers.Timer();
//开始停止
private void btnManage_Click(object sender, EventArgs e)
{
btnManage.Text = btnManage.Text == "开始" ? "停止" : "开始";
this.timer1.SynchronizingObject = this;
this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(timer1_Elapsed);
this.timer1.Interval = 20000;
this.timer1.Enabled = !this.timer1.Enabled;
GC.KeepAlive(timer1);
}
//事件
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (flag)
{
flag = false;
if (!Products.IndexNormalData())//创建普通产品索引
Application.Exit();
if (!Products.IndexVipInfoData())//创建VIP产品索引
Application.Exit();
flag = true;
}
}
应该不是两分钟
有问题的还请大大们 指出 我是菜鸟
2分钟应该是这样:
this.timer1.Interval = 2 * 60 * 1000;