473,763 Members | 4,808 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Threadin g.Timer fires too quickly!

I am running a windows service that takes actions based on a couple
System.Threadin g.Timers. The intervals are usually short... based on
the time of day, anywhere between 1 and 5 minutes. Recently however,
the event that was firing based on the timer started firing rapidly; it
fired about 9000 times in a minute and a half. After the minute and a
half was up, it returned to normal behavior!

.... just wondering if anyone has experienced this strange behavior and
if they've found a solution. There was another posting on this a few
months ago, but there were no responses
(http://groups-beta.google.com/group/...5803fd38be2abe)

Much thanks for any help!

Nov 16 '05 #1
3 2338
Kenny wrote:
I am running a windows service that takes actions based on a couple
System.Threadin g.Timers. The intervals are usually short... based on
the time of day, anywhere between 1 and 5 minutes. Recently however,
the event that was firing based on the timer started firing rapidly; it
fired about 9000 times in a minute and a half. After the minute and a
half was up, it returned to normal behavior!

... just wondering if anyone has experienced this strange behavior and
if they've found a solution. There was another posting on this a few
months ago, but there were no responses
(http://groups-beta.google.com/group/...5803fd38be2abe)

Much thanks for any help!


"based on time of day", could it be that there are specific times
that are between the "usual" periods that end up with an interval
of 1/100 seconds? Say "time < 08:00" = 5 minutes,
"time > 08:00" = 1 minutes, then what about 08:00 itself?
How exactly are you calculating that interval?

--
Hans Kesting
Nov 16 '05 #2
I have a loop that does some work. In my config file, I specify a
value "peak hours". At the top of the loop, I check to see what time
it is. If I am within the peak hours, my interval is 1 minute,
otherwise it is 5 minutes. I set the timer with one of those values.
The body of the loop does some work, and at the bottom of the loop, I
wait for an AutoResetEvent that is set by the callback of the Timer.

I've debugged the code and it just doesn't seem possible for the
interval to have a value other than 1 or 5 because I'm using an if-else
to set the interval value. If it's within peak hours, set it to 1,
else 5.

Here is the main bit of the code...
public void StartMessages(o bject state)
{
int timeBetweenRequ ests;
Timer requestTimer;
AutoResetEvent[] events = new AutoResetEvent[2];

while( true )
{
timeBetweenRequ ests = GetRequestInter val();

for(int i = 0; i < m_Requestors.Co unt;)
{
RequestorData rd = (RequestorData) m_Requestors[i];

requestTimer = new Timer(new TimerCallback(t his.SignalNextR equest),
m_SendNextReque st,
timeBetweenRequ ests, Timeout.Infinit e);

try
{
if(rd.Type == RequestorType.D ialUp)
{
DoDialUpRequest (rd);
}
else if(rd.Type == RequestorType.N etwork)
{
DoNetworkReques t(rd);
}
else
{
throw new V1ErrorExceptio n(ErrorInfo.Inv alidRequestorTy pe);
}
}
catch(V1ErrorEx ception v1Err)
{
ExceptionManage r.Publish(v1Err );
}

events[0] = m_SendNextReque st;
events[1] = m_EndRequestLoo p;

int eventIndex = WaitHandle.Wait Any(events);
requestTimer.Di spose();

if(eventIndex != 0)
{
Debug.WriteLine ("Signal received to kill request group. Ending
request loop.");
return;
}
}
}
}

private int GetRequestInter val()
{
DateTime now = new DateTime(DateTi me.Now.Ticks);
int currentTime = now.Hour * 100 + now.Minute;

if( currentTime >=
Convert.ToInt32 (MonitorConfigR eader.MonitorSe ttings("peakHou rsStart"),
CultureInfo.Inv ariantCulture) &&
currentTime <=
Convert.ToInt32 (MonitorConfigR eader.MonitorSe ttings("peakHou rsEnd"),
CultureInfo.Inv ariantCulture) )
{
return
Convert.ToInt32 (MonitorConfigR eader.MonitorSe ttings("peakHou rsRequestInterv al"),
CultureInfo.Inv ariantCulture);
}
else
return
Convert.ToInt32 (MonitorConfigR eader.MonitorSe ttings("offPeak HoursRequestInt erval"),
CultureInfo.Inv ariantCulture);
}

Nov 16 '05 #3
Kenny wrote:
I have a loop that does some work. In my config file, I specify a
value "peak hours". At the top of the loop, I check to see what time
it is. If I am within the peak hours, my interval is 1 minute,
otherwise it is 5 minutes. I set the timer with one of those values.
The body of the loop does some work, and at the bottom of the loop, I
wait for an AutoResetEvent that is set by the callback of the Timer.


I've been running into a similar situation. For me it has only been on
setting a very long dueTime > 8 days or so. Instead of waiting that
amount of time, it fires immediately.

I tried to narrow it down, to a specific dueTime, but it seemed that as
the system time progressed, the dueTime that started to demonstrate this
problem decreased. Currently, it seems that if I try to set a dueTime
that will expire after a fluctuating time on 2005-04-07 it demonstrates
this behavior. And the time seems to be getting slowly earlier...

I'm curious what will happen as that date gets closer. Will it fire
right away with a dueTime as low as 1 minute then? After that point in
time, what date will start giving this problem? It definitely seems
like some sort of bug to me, though what they could have done to
demonstrate this odd behavior is beyond me.
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
16910
by: Peter Johnsson | last post by:
How come the eventhandler for the timer's elapsed time event is called over and over again, even though the AutoReset property is set to false, if you assign a new value to the timer objects interval property inside the event handler? Example follows: Constructor: mTimer = new System.Timers.Timer(20000); mTimer.AutoReset = false;
3
5606
by: ELO | last post by:
Hi all Every week, I need to get two files on a remote server. I have developped a C# Windows Service with two System.Threading.Timer to do this task For the first one, the delay (TimeSpan dueTime) is always set to 6 days, 23 hours, 59 minutes, .. Some weeks ?!?, the timer restarts immediately after its execution (and loop indefinitely). I have made a lot of tests and this issue does not occur with a delay < 1 day .. Any suggestion
4
4082
by: Hagay Lupesko | last post by:
Hi, I've encountered a strange phenomena which appears to me as a bug: I have an engine that uses a System.Threading.Timer to invoke a delegate every X minutes. The code looks something like this: TimerCallback callBack = new TimerCallback(Run); // run is obviously a method
5
5999
by: caulker | last post by:
I have a simple Windows Service with a timer (system.timer). The service seems to run just fine when I have the Timer = 1 minute, but when I set the Timer = 15 minutes it only fires once ... then appears to stop. any help is greatly appreciated...
6
2880
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a TimerState object similar to the example in the System.Threading.Timer documentation. The method which handles the timer events, among other things, periodically calls a method in this TimerState object which raises an event to the startup form,...
1
3300
by: Paul Tomlinson | last post by:
Question about a System.Threading.Timer object and the "state" object you pass to it... Timer stateTimer = new Timer( = new TimerCallback( OnTimer ), o, 1000, 1000); I have an array of timer objects which all fire into my OnTimer( object state ) function very nicely. I pass in an object "o" on creation of this timer which I subsequently get passed to me in my OnTimer function. Now in the OnTimer function I want to modify the object...
2
13216
by: linesh.gajera | last post by:
Hi Guys, I am creating a Windows service that call a routine at given interval. Once routine is complete, windows service should wait for 5 minutes and then call the routine again. I was using System.Timers.Timer but i had to remove it because of known bug(842739). Now i am using System.Threading.Timer. It executes routine fine but the delay time is sporadic, sometimes it executes routine after 5 minutes, sometimes 10 minuete, 13...
2
2214
by: cntams | last post by:
All, I have a Windows Service and it has one System.Timers.Timer that fires every 500 milliseconds. Now I have noticed that there's a bug in System.Timers.Timer when it's being used combined with Windows Service. That is, the Timer won't fire again once it's stopped (Timer.Stop() or Timer.Enabled = False) (http://support.microsoft.com/kb/842793/en-us). Instead of using Threading.Timer, can I just have the code to run inside the...
8
3373
by: Ollie Riches | last post by:
I'm looking into a production issue related to a windows service and System.Timers.Timer. The background is the windows service uses a System.Timers.Timer to periodically poll a directory location on a network for files and then copies these files to another location (on the network) AND then updates a record in the database. The file copying is performed before the database update because the file system is not transactional. The code...
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9997
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9937
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.