Solved

VB.NET Stopwatch devouring Processor - alternatives?

Posted on 2006-07-20
3
370 Views
Last Modified: 2008-01-09
Visual Studio 2005 Pro
-------------------------------------------
Dim objTimer As Stopwatch = New Stopwatch

    'Interval in timecode (00:00:00.0000000) at which the monitor will query server for a response. Default: 5 minutes = 00:05:00.0000000
    Dim strTimer_Interval As String

Sub Execute_Timer()

        strTimer_Interval = My.Settings.strTimer_Interval

        objTimer.Start()

        While objTimer.Elapsed.ToString < strTimer_Interval
        End While

        objTimer.Reset()
        Run_Program()

End Sub
-------------------------------------------

The above code is used as part of a monitoring program I have written. The idea is that the Run_Program function which contains all of the main processing functions should only occur every 15 minutes (or whatever value you enter in the config file).

After Run_Program(), I call the Execute_Timer() function shown above. The idea is that nothing is supposed to happen for the next 15 minutes. After 15 minutes, Run_Program() again, etc...

The trouble is the WHILE statement is jacking my Processor to 100% utlization. Which, *duh*, makes sense now that I think about it, but I need an alternative solution (ideally one that can coded into the application (example, not looking for cron or Scheduled Task solutions) that doesn't burn my clock up!

Thanks!
0
Comment
Question by:dalsym
  • 2
3 Comments
 
LVL 24

Accepted Solution

by:
Justin_W earned 500 total points
ID: 17150314
Use this instead of a while loop:
    System.Threading.Thread.CurrentThread.Sleep()
0
 
LVL 4

Author Comment

by:dalsym
ID: 17150380
perfect

thanks!
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 17150394
You're welcome!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

774 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