Jay
Jay

Reputation: 539

How to pause the timer in c#?

I have a timer in my code with a 10s interval.

When the time elapses I will do some checking. It may takes more than 10s for checking and some update jobs.

However, if I didn't stop the timer, it seems the checking will execute every 10s. If I call stop(), the timer cannot be started again. i.e. 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 before the checking is done.

Can anyone help?

Upvotes: 4

Views: 9415

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062855

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.

Upvotes: 5

Related Questions