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;
            }
        }

解决方案 »

  1.   

    没怎么用过,但是this.timer1.Interval = 20000;
    应该不是两分钟
      

  2.   

    System.Timers.Timer  是以多线程模式  启动的  如果还涉及到 窗体操作   建议不要使用   直接使用Forms.Timer吧      这个timer会在主线程里执行!
         有问题的还请大大们  指出  我是菜鸟
      
      

  3.   

    this.timer1.Interval = 20000;//20秒
    2分钟应该是这样:
    this.timer1.Interval = 2 * 60 * 1000;
      

  4.   

    使用异步线程通迅,等我试下,好长时间没搞WinFrom了