Solved

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

Posted on 2004-08-27
7
370 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
base64 decode encode 12 134
how to send memory stream from ics Client To ics server ? 11 114
Hide vba in gp 7 95
Using Third Party DLL with Access VBA 14 18
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
This is an explanation of a simple data model to help parse a JSON feed
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 …

832 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