Possible Duplicate:
Synchronizing a timer to prevent overlap
I have a Threading.Timer in my class.
System.Threading.Timer timer;
TimerCallback cb = new TimerCallback(ProcessTimerEvent);
timer = new Timer(cb, reset, 1000, Convert.ToInt64(this.Interval.TotalSeconds));
and defined a callback for it.
private void ProcessTimerEvent(object obj)
{
if(value)
MyFunction();
}
When run it, re-running callback before myfunction to complete.
How to pause Threading.Timer to complete myfunction?
It is not necessary to stop timer, you could let the timer continue firing the callback method but wrap your non-reentrant code in a Monitor.TryEnter/Exit. No need to stop/restart the timer in that case; overlapping calls will not acquire the lock and return immediately.