使用了system.timers.timer以后,如何让timer暂停?

dxcanadl 2009-03-02 05:41:19
我想做个按钮,点暂停就暂停,再点一次就继续。。不知道怎么实现?
这个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());
}
...全文
1144 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
lifang930 2012-05-16
  • 打赏
  • 举报
回复
我也遇到此问题怎么解决?
deyter 2009-03-02
  • 打赏
  • 举报
回复
t.start();
t.stop();
cppfaq 2009-03-02
  • 打赏
  • 举报
回复
t.Enabled = false

JF
wanabe 2009-03-02
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 liujiayu10 的回复:]
t.Enabled = false
[/Quote]..
hhxxcj 2009-03-02
  • 打赏
  • 举报
回复
呵呵,楼主已经解决了吧,发分吧,我接啦
还有,你也可以用它的挂起事件,也能办到,休眠也能办到
dai78 2009-03-02
  • 打赏
  • 举报
回复
在里面加个判断,如果是暂停,就跳过执行语句,否则就执行代码
麻子Mozart 2009-03-02
  • 打赏
  • 举报
回复
d
lovehongyun 2009-03-02
  • 打赏
  • 举报
回复
t.Enabled = false
zincy 2009-03-02
  • 打赏
  • 举报
回复
kkkkkkkkk
ztenv 2009-03-02
  • 打赏
  • 举报
回复
timer.enabled=!timer.enabled;
hecong875 2009-03-02
  • 打赏
  • 举报
回复
正解出来了 ! 结帖子吧
liujiayu10 2009-03-02
  • 打赏
  • 举报
回复
t.Enabled = false
wzuomin 2009-03-02
  • 打赏
  • 举报
回复

t.Enabled = true

t.Enabled = false

启动或暂停

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧