Solved

VB.NET Stopwatch devouring Processor - alternatives?

Posted on 2006-07-20
3
366 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

895 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

13 Experts available now in Live!

Get 1:1 Help Now