Solved

Windows service with Timer...prevent method from running over itself on OnTimer event.

Posted on 2004-08-27
7
377 Views
Last Modified: 2010-04-17
Hi all,

I have a VB.NET 2002 windows service that runs on one of my servers that polls an IBM AS400 file and downloads records into an XML document for processing.  The issue I'm currently experiencing is that I need the records to be processed in order where I have one XML per record, but some records take longer to generate an XML doc for than others.  

I have a Timer object in the service that is set at an interval of 750ms, but it appears that if I am generating a larger record that takes longer than that to save off, the Timer event clicks again and gets the next record and may finish it before the first record, therefore I'm knocked out of sequence.

Aside from setting the Timer Interval value higher, is there a way I can 'trick' the service to ensure that the current method run is finished before the next tick occurs?

Thanks,
-Rich
0
Comment
Question by:RichWallace
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 6

Accepted Solution

by:
PreachDotNet earned 125 total points
ID: 11913822
I usually stop the timer at the beginning of execution and then restart it at the end.
0
 
LVL 22

Expert Comment

by:cookre
ID: 11913876
Yup.
0
 
LVL 6

Expert Comment

by:PreachDotNet
ID: 11913970
So much conveyed in so few words.
Lend me 50,000 points I want a certificate, something to replace the 25M swimming award that takes pride of place over my mantelpiece.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:RichWallace
ID: 11914168
Thanks, I did try that and my records are still coming down out of seqeunce.  Any other details?
0
 
LVL 1

Author Comment

by:RichWallace
ID: 11914302
Well, not quite what I had wanted, but I did put the Stop and Start methods in but still ahd to set my Interval value to 1s which I guess is acceptable :)
0
 
LVL 22

Expert Comment

by:cookre
ID: 11914648
As Peach indicated, disabling the timer upon entry to the timer interrupt handler and re-enabling just before exiting ensures the timer interrupt handler doesn't commit ritual sepuku.  

If records are not in the desired or expected order, that's another problem.



Paul: That's, uh, only 25 500pt A's.  Pick a busy TA, take a month off, and spend 18 hours each day on EE.
0
 
LVL 1

Author Comment

by:RichWallace
ID: 11916895
Not necessarily, I only grab one record at a time based on the max time value.  Thanks again.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Six Sigma Control Plans

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question