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 do开发者_运维问答ne.
Can anyone help?
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.
精彩评论