|
-
Dec 16th, 2006, 07:50 PM
#3
Re: monitoring elapsed time with the stopwatch
As Buoy suggests, this is not a job for a Stopwatch. A Stopwatch is supposed to tell you how much time has elapsed when you ask, not automatically tell you when a specific amount of time has elapsed. With a Stopwatch you start it, do something, then check how long it took. You should indeed be using a Timer.
Only the Windows.Forms.Timer is in the VS 2005 Toolbox by default. You want to use a Timers.Timer. You can add it to the Toolbox manually and then add one to your Service in the designer or you can create one in code. If you do it in code make sure you declare the variable WithEvents.
Basically you would set the Interval to 5000 (milliseconds) and then handle the Elapsed event. You would perform your action in the Elapsed event handler. By default that event will only be raised once. If you set the AutoReset property to True then it will be raised repeatedly on the specified Interval until you explicitly Stop it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|