tags:

views:

282

answers:

2

I have a timer in my code and the interval is 10s

When the timer elapsed, I will do some checking, and it may takes more than 10s for checking and some update jobs.

However, if I didn't stop the timer, seems the checking will execute every 10s ... If I call the stop(), seems the timer cannot be start again ... ie something like:

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

I just want another 10s to check again after the before checking is done. anyone can help?

+1  A: 

Maybe try setting the timer enabled property to false when you don't want it to run, the set it back to enabled when you're ready to go again.

Robb
For `System.Timers.Timer` and `System.Windows.Forms.Timer`, `Start()` is simply implemented as `Enabled=true`, and `Stop()` is `Enabled=false`...
Marc Gravell
Ah didn't realize that. Thanks.
Robb
+2  A: 

Assuming that is something like winforms or WPF, that should work. Are you sure you aren't getting an exception or something?

If it is web, all bets are off ;-p You should perhaps clarify if this is System.Threading.Timer, System.Timers.Timer or System.Windows.Forms.Timer, or something else.

Marc Gravell