Solved

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

Posted on 2004-08-27
7
364 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
bunnyEars challenge 6 65
count8 challlenge 13 87
mapShare challenge 13 69
python question 5 60
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
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 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…
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 …

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now