One thing that you could do would be to set a flag when you enter your timer
handler. You will ignore any timer events while the flag is set, and reset
it when you finish your handler:
example:
// warning, I'm writing this "off the cuff", so there might be syntax errors
private bool TimerHandlerInProgress;
public void MyTimerCallback(object state)
{
lock(this)
{
if(this.TimerHandlerInProgress)
return; // ignore the timer elapse-- we are still handling the
last one
else
this.TimerHandlerInProgress = true;
}
try
{
// process your timer event here....
}
finally
{
// reset the handled flag
lock(this)
{
this.TimerHandlerInProgress = false;
}
}
}
"Naveen Mukkelli" <Na************@discussions.microsoft.com> wrote in
message news:05**********************************@microsof t.com...
Hi,
Currently I'm using System.Threading.Timer to perform some tasks
periodically,
lets say every minute.
How can we disable this timer(System.Threading.Timer) so that the time
spent
in the callback method is not counted.
Do we have an equivalent of
System.Timers.Time.Enabled
property in System.Threading.Timer class?
Kindly let me know.
Cheers,
Naveen.