Solved

VB.NET Stopwatch devouring Processor - alternatives?

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 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

17 Experts available now in Live!

Get 1:1 Help Now