?
Solved

VB6 loop taking a bunch of resources.

Posted on 2012-09-16
10
Medium Priority
?
614 Views
Last Modified: 2012-09-19
Hi,

I need to build an eternal loop in a VB6 application that will be monitoring a variable change, of course this loop is taking a bunch of resources from the system, over 75% in task manager. Suggestions on how to perform this with minimal resources consumption are welcomed.

Regards,
0
Comment
Question by:lxfdirs
  • 2
  • 2
  • 2
  • +4
10 Comments
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 750 total points
ID: 38403165
Firstly, do make sure that you have one or more DoEvents in the loop.
Then consider using a timer so that the check is only done at intervals.
0
 

Accepted Solution

by:
GS2907 earned 750 total points
ID: 38403167
Alternate way is to drop a timer control on your form and on its timer event, to the processing. You can also adjust the frequency of the timer.
0
 
LVL 50

Expert Comment

by:Martin Liss
ID: 38403226
If you already have the code for the loop please show it to us,
0
Independent Software Vendors: 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!

 
LVL 46

Expert Comment

by:aikimark
ID: 38403956
If you're doing this for debugging purposes, you can do the same thing by setting a watch on the variable or an expression involving the variable.

You can also create dynamic breakpoints programmatically with one of the following methods:
If variable-related-condition Then
    Stop
End If

Or

Debug.Assert (variable-related-condition)

=============
What type of monitoring are you trying to accomplish?  In other words, what is the context for this question?
0
 

Author Comment

by:lxfdirs
ID: 38403959
Hi,

Appreciate your comments.
The loop is a simple one:
do
    doevents()
    if x = 3             ' x is set by another process which raises an event
        do something
    end if
loop while(1)

In my development station it takes 50% of the CPU. If I run the application on  Windows Server 2008 it takes 99%.


Regards,
0
 
LVL 46

Expert Comment

by:aikimark
ID: 38403973
how frequently can variable x change?

If it raises an event, why not put the check for the variable in the event code?
0
 
LVL 50

Expert Comment

by:Martin Liss
ID: 38403987
What is the code behind "do something"? It must be that code that's causing the problem because your loop, while written in an unusual fashion, is pretty simple.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 38404099
If you ABSOLUTELY need to keep the code "in the loop" (can't use a timer for whatever reason), then add s SMALL call to Sleep() in your loop to throttle it back:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

...
    do
        doevents()
        if x = 3             ' x is set by another process which raises an event
            do something
        end if
        Sleep 50
    loop while(1)

Open in new window

0
 
LVL 4

Expert Comment

by:amit_panjwani
ID: 38413264
if you want to keep code reusable - either create a class with API calls or use custom ActiveX control which is lazy.

But MartinLiss does has a point - what is program doing behind loop .
0
 

Author Closing Comment

by:lxfdirs
ID: 38413365
Appreciate all your comments, guys. A timer control with intervals worked well.<br /><br />Regards,
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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

807 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