Solved

VB.NET Stopwatch devouring Processor - alternatives?

Posted on 2006-07-20
3
374 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 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