Solved

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

Posted on 2004-08-27
7
372 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
  • 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
Technology Partners: 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

Technology Partners: 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!

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

735 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