Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

V.B Application system resource usage

Status
Not open for further replies.

Dav1e

Programmer
Nov 4, 2001
7
0
0
GB
Hi,

I have writen a VB App. that loops every so many seconds and retrieves mail from a Pop3 host. To delay the loop I use a Timer object and allow the user to set the delay time.

When the app. is running though it seems to use a large ammount of system resources, particularly processsor time which seems to shoot up to around 90 to 100%, and doesn't drop off even when the system is waiting for the delay time to pass.

Any ideas on why this is happening or how to reduce the requirements of the tool gratefully recieved.


thanks in advance

Davie
 
As a test, try running the routine from a button click event and monitor the processor usage, preferably with some mail to retrieve. I suspect the call to the POP3 host and the retrieval of mail is taking longer than the timer interval and monopolizes the CPU while it's working.

Some things that may help:
If your call has a loop in it that keeps firing until done, try putting a DoEvents() in it - this makes the program pause so other things may use the CPU.
Otherwise, you may wish to put the POP3 call in an ActiveX EXE so that it is running asynchronously in another thread. This will let your program do other things instead of waiting for the call to complete, if that is an issue.

While I'm thinking about it, what kind of processor/speed are you running this on. Worse case senario there would be to upgrade :). -Chris Didion
Matrix Automation, MCP
 
DoEvents does not alleviate the cpu usage. It gives up to allow things to happen, but when nothing needs to be done, the app gets right back to sucking up cycles.

To give up the CPU you should use the sleep function. This actually makes the application inactive for the time period. REALLY Inactive! No repaints or keys get processed etc. The system will wake the app up after the sleep period has expired. To remain semi responsive use brief sleeps combined with DoEvents.

[tt]Public declare Sub Sleep Lib "kernel32" alias "Sleep"(Byval dwMilliseconds as Long)[/tt]

I actually prefer to wrap this in a sub that does a DoEvents too. Sometimes I even have it handle the short pauses and function on seconds instead of milliseconds.
something like [tt]
Public Sub WaitSome(lSeconds as long)
dim ln0 as long
ln0 = lSeconds * 4
while ln0 > 0
sleep 250
Doevents
ln0 = ln0 -1
wend
end sub
[/tt]

Wil Mead
wmead@optonline.net

 
Thanks,

The Sleep method, combined with the DoEvents works really well, it now only uses around 5% of the system resources while running. It was the loop waiting for the Timer to fire that was causing the problems.

Cheers again

Davie
 
Glad that worked, but you shouldn't have a loop waiting for the timer to fire. You should be running your POP3 code in response to the timer_timer event. Then there's no looping and waiting, just waiting. -Chris Didion
Matrix Automation, MCP
 
If you are working with forms, it's maybe easier to work with with a combination of the timer and a textbox. No CPU problems (<>doevents) and your program remains responsive (<>sleep).

Sub Text1_Change()
type here your code
End Sub

Sub Timer1_Timer()
Text1.Text = Time ' Update time display.
End Sub

bono
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top