I have a service that is driven by a timer that fires every 5 seconds.
For the most part, it works fine. But every once in a while the timer
fires twice. In the log I can see that when it fires twice, there are
two threads running. This causes problems so I need to find a way to
fix it.
So, my question is, do I need to use a Monitor to lock in my
timer_elapsed event handler?
Thanks for any advice...
Brian
Greg - 21 Dec 2005 17:19 GMT
What sort of timer did you use? I had problems with the timer present
in the toolbox due to changes in controls on the form getting in the
way of the timer's elapsed method. I'm wondering if the timer is firing
twice because the first time it should have been firing something else
was happening.
Switching to a System.Timers.Timer solved the issues that I had.
Greg.
Brian P - 21 Dec 2005 17:27 GMT
I am using a System.Timers.Timer.
It is a windows service, so it isn't form based.
Thanks for the thought, tho.
-B
> What sort of timer did you use? I had problems with the timer present
> in the toolbox due to changes in controls on the form getting in the
[quoted text clipped - 5 lines]
>
> Greg.
Ignacio Machin ( .NET/ C# MVP ) - 21 Dec 2005 18:51 GMT
Hi,
Maybe what happen is that in those moments the timer handler takes more than
5 seconds from the moment the timer elapsed for the last time.
a lock may be of help here.
cheers

Signature
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
>I have a service that is driven by a timer that fires every 5 seconds. For
>the most part, it works fine. But every once in a while the timer fires
[quoted text clipped - 7 lines]
>
> Brian
Brian P - 22 Dec 2005 15:40 GMT
From my log, it seems that the two timer events occur concurrently.
It's almost as if the timer firest two elapsed events at the same time.
Because the work occurs in two different threads. (One for each event?)
I did add a lock and we'll see what that does..
--Brian
> Hi,
>
[quoted text clipped - 3 lines]
>
> cheers