471,318 Members | 3,223 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

Timer Elapsed Firing Twice

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
Dec 21 '05 #1
4 7342
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.

Dec 21 '05 #2

I am using a System.Timers.Timer.

It is a windows service, so it isn't form based.

Thanks for the thought, tho.

-B
Greg wrote:
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.

Dec 21 '05 #3
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

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Brian P" <no******@all.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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

Dec 21 '05 #4

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
Ignacio Machin ( .NET/ C# MVP ) wrote:
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

Dec 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Philip Wagenaar | last post: by
4 posts views Thread by Liverpool fan | last post: by
1 post views Thread by Adam Benson | last post: by
8 posts views Thread by =?Utf-8?B?RGF2ZSBCb29rZXI=?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.