Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.NET Stopwatch devouring Processor - alternatives?

Posted on 2006-07-20
3
Medium Priority
?
387 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 2000 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

Industry Leaders: 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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

715 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