Services & Timers

F

fatica

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
 
F

fatica

Thats what programming till 3 in the morning will get ya, a blatant
disregard for the obvious.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top