【问题标题】:How to pause the timer in c#?如何在c#中暂停计时器?
【发布时间】:2012-01-22 10:21:26
【问题描述】:

我的代码中有一个计时器,间隔为 10 秒。

当时间过去了,我会做一些检查。检查和一些更新作业可能需要 10 多秒。

但是,如果我没有停止计时器,似乎检查将每 10 秒执行一次。如果我拨打stop(),计时器将无法再次启动。 即类似:

    protected void timer_elapsed(object sender, EventArgs args) 
    {
        __timer.Stop();
        //Some checking here more than 10s
        __timer.Start();
    }

我只想在检查完成之前再检查一次。

谁能帮忙?

【问题讨论】:

  • 也许当你不想让它运行时尝试将 timer enabled 属性设置为 false,当你准备好再次运行时将它设置回启用。

标签: c# timer


【解决方案1】:

假设这类似于 winforms 或 WPF,应该工作。你确定你没有得到异常或什么?

如果是网络,所有赌注都没有;-p 你或许应该澄清这是System.Threading.TimerSystem.Timers.Timer 还是System.Windows.Forms.Timer,或者其他什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-09
    • 2012-06-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多