lxfdirs
asked on
VB6 loop taking a bunch of resources.
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,
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,
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you already have the code for the loop please show it to us,
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-conditio n)
=============
What type of monitoring are you trying to accomplish? In other words, what is the context for this question?
You can also create dynamic breakpoints programmatically with one of the following methods:
If variable-related-condition
Stop
End If
Or
Debug.Assert (variable-related-conditio
=============
What type of monitoring are you trying to accomplish? In other words, what is the context for this question?
ASKER
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,
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,
how frequently can variable x change?
If it raises an event, why not put the check for the variable in the event code?
If it raises an event, why not put the check for the variable in the event code?
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.
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)
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 .
But MartinLiss does has a point - what is program doing behind loop .
ASKER
Appreciate all your comments, guys. A timer control with intervals worked well.<br /><br />Regards,