Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / December 2005

Tip: Looking for answers? Try searching our database.

Timer Elapsed Firing Twice

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian P - 21 Dec 2005 17:01 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.