473,403 Members | 2,222 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,403 software developers and data experts.

Services & Timers

Hi all,

I've written a windows service in .net 2.0 running on a windows 2003
server. I've hooked the system timer elapsed event to run some very
time consuming code. This code processes a list of jobs and when its
done, clears out that list. However, when the code takes longer to
execute than the timer interval, all heck breaks loose. The elapsed
code is fired again, yet, its still working on the list. What exactly
has happened here? Do I have two threads all of a sudden or did the
first Elapsed code get blocked somehow or what? What I can say is if I
have the interval set low enough where its certain to elapse before the
code is completed, I'll get the jobs in the list completed 5 or 6 times
each with all sorts of little race condition bugs intermingled in
there.

So, to make a long story short, whats the best way to ensure that the
code in the Elapsed handler doesn't get called if its still running?
I could update a field in the database, but I thought I'd ask first.

Thanks,

Mike Fatica

Feb 15 '06 #1
2 1191

Stop the timer when you call the method.

Start it up again when it finishes.

fa****@gmail.com wrote:
Hi all,

I've written a windows service in .net 2.0 running on a windows 2003
server. I've hooked the system timer elapsed event to run some very
time consuming code. This code processes a list of jobs and when its
done, clears out that list. However, when the code takes longer to
execute than the timer interval, all heck breaks loose. The elapsed
code is fired again, yet, its still working on the list. What exactly
has happened here? Do I have two threads all of a sudden or did the
first Elapsed code get blocked somehow or what? What I can say is if I
have the interval set low enough where its certain to elapse before the
code is completed, I'll get the jobs in the list completed 5 or 6 times
each with all sorts of little race condition bugs intermingled in
there.

So, to make a long story short, whats the best way to ensure that the
code in the Elapsed handler doesn't get called if its still running?
I could update a field in the database, but I thought I'd ask first.

Thanks,

Mike Fatica

Feb 15 '06 #2
Thats what programming till 3 in the morning will get ya, a blatant
disregard for the obvious.

Feb 15 '06 #3

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

Similar topics

0
by: Rajesh Abraham | last post by:
I am looking to use Timers in my Windows Service application and just realised that apart from the forms Timer, there is also System.Threading,Timer and System.Timers.Timer. When should I prefer...
1
by: Jason | last post by:
Hi all just a quick question. I have a windows service with a "Catalogue" class. I would like to know: if i put two "ServiceTimer" objects in my service 1. Do they run in separate threads...
1
by: jeff | last post by:
Greetings; Newbie here, please forgive my ignorance of the vb.net threading model. I am developing a windows service which is driven by a variable number of timers. All timers use the same...
2
by: jeff | last post by:
Greetings; Newbie here, please forgive my ignorance of the vb.net threading model. I am developing a windows service which is driven by a variable number of timers. All timers invoke the same...
5
by: Eric | last post by:
Hi I built a service that watch file in a directory. I use a simple filewatcher and add a handler to do something when a file is created. I have the following problem. I can build it, I can...
0
by: brunft | last post by:
I was testing this with .NET Framework 2.0. Exceptions in the Elapsed event handler of a System.Timers.Timer are ignored, they are not handled by the runtime and not reported (when running...
4
by: Kürşat | last post by:
Hi all, I use System.Windows.Forms.Timer with a Windows service but nothing happens after given interval elapsed. It seems timer event does not occur. How can I use timers with Windows...
2
by: sdstraub | last post by:
I have created 5 services in my project, in the 1st service I set servicestorun = array of all 5 services, I have a project installer with 5 service installers, one for each service. I have code...
8
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...
4
by: Tomas Andersson | last post by:
I have two questions regarding services. First of. Is there any problem with creating VB9 services running timer events om Winxp? I built a service App and it installs and runs but the timer...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.