日期:2014-05-18  浏览次数:21869 次

使用了system.timers.timer以后,如何让timer暂停?
我想做个按钮,点暂停就暂停,再点一次就继续。。不知道怎么实现?
这个system.timers.timer好像一运行起来就不停了...

  System.Timers.Timer t = new System.Timers.Timer(tTime*1000);//实例化Timer类,设置间隔时间为10000毫秒; 
  t.Elapsed += new System.Timers.ElapsedEventHandler(theout);//到达时间的时候执行事件; 
  t.AutoReset = true;//设置是执行一次(false)还是一直执行(true); 
  t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件; 
下面是theout内容

  public void theout(object source, System.Timers.ElapsedEventArgs e)
  {
  Random ro = new Random();
  urlTxt = ro.Next(listC);
  webBrowser1.Navigate("http://www.google.com/?t=w&p=1&q=" + list[urlTxt].ToString());
  }

------解决方案--------------------
 
 t.Enabled = true 
 或
 t.Enabled = false

启动或暂停