473,394 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 7834
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: David | last post by:
Hi There! I'm using Timer control to record how long my application perform certain tasks. However, apparently Timer control is not doing its' job (i.e. Not firing Tick event) while my...
9
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null;...
4
by: Dan | last post by:
Hi, I have a timer on a form (System.Windows.Forms.Timer - Framework 1.1) that is set to 60 seconds as sort an of inactivity monitor. If 60 seconds have elapsed without any user activity I want...
11
by: Philip Wagenaar | last post by:
Hello, I am using a timer object in my Windows Forms Application. Does the code in ..elapsed event run in a diffrent thread? If the interval is set to 10 milliseconds and the time to execute the...
4
by: Liverpool fan | last post by:
I have a windows application written using VB .NET that encompasses a countdown timer modal dialog. The timer is a System.Timers.Timer with an interval of 1 second. AutoReset is not set so accepts...
7
by: RobKinney1 | last post by:
Hello, Wow...I have one for you all and hopefully I am not understanding this timer object correctly. I have a timer setup that pulses a connection through a socket every 60 seconds. But it...
9
by: archana | last post by:
Hi all, I want to know about interval of timer. I am using timer in windows service.I head somewhere that when i set interval property of timer while setting interval, restart time of Pc is...
1
by: Adam Benson | last post by:
Hi, We have figured out that System.Timers.Timer should be avoided because it occasionally stops firing. So, we dutifully began switching over to System.Threading.Timer but somebody at work...
8
by: =?Utf-8?B?RGF2ZSBCb29rZXI=?= | last post by:
I have a Timer that I set to go off once a day, but it frequently fails! In order to debug I would like to be able to check, at any moment, whether the Timer is enabled and when it will next...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.