M
Matt
I have a windows service that is using the timer object from
System.Timers to fire every minute and do some work. Occasionally
that work takes longer than a minute - and I don't want the elapsed
event to fire again if a previous event is still occurring.
In the elapsed event the first thing that I do is stop the timer.
Once the work is complete I start the timer again. My only concern is
that in the MSDN docs for this object it says that the timer object is
multithreaded and so if another thread has been spun off - calling the
stop event might not prevent reentrancy into the method.
The example code provided to keep this race condition from happening
is fairly complex (yes - I am "thread challenged") and was hoping that
there might be an easier way to see if the previous event is still in
motion, and if so keep the event from firing. I was going to use a
boolean value that gets set when execution begins and is reset when it
ends. It seems like a straightforward solution - I just wanted to get
some thoughts on it.
Any help or nudges in the right direction would be greatly
appreciated.
Thanks,
Matt Childs
System.Timers to fire every minute and do some work. Occasionally
that work takes longer than a minute - and I don't want the elapsed
event to fire again if a previous event is still occurring.
In the elapsed event the first thing that I do is stop the timer.
Once the work is complete I start the timer again. My only concern is
that in the MSDN docs for this object it says that the timer object is
multithreaded and so if another thread has been spun off - calling the
stop event might not prevent reentrancy into the method.
The example code provided to keep this race condition from happening
is fairly complex (yes - I am "thread challenged") and was hoping that
there might be an easier way to see if the previous event is still in
motion, and if so keep the event from firing. I was going to use a
boolean value that gets set when execution begins and is reset when it
ends. It seems like a straightforward solution - I just wanted to get
some thoughts on it.
Any help or nudges in the right direction would be greatly
appreciated.
Thanks,
Matt Childs