CPU Usage

T

Tony B.

Is there a way to control the CPU usage for a process? I've built a process
using VBA in an office application however, when the process runs, it bumps
the CPU usage to 100% thus taking full control of the computer. There must
be a way to set the priority.

Any help would be GREAT.

Thanks.

Tony B.
 
J

Jonathan West

Tony B. said:
Is there a way to control the CPU usage for a process? I've built a process
using VBA in an office application however, when the process runs, it bumps
the CPU usage to 100% thus taking full control of the computer. There must
be a way to set the priority.

Any help would be GREAT.

Put a few DoEvents commands inside the innermost loop of your process. This
will cause the system to release the CPU for long enough to alloow the
Windows message queue to be polled.

If this is not sufficient, then you can temporarily halt the process by
using the Sleep command.

Add this line above the first Sub or Function in your module

Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds
As Long)

Then, whenever you want to put a pause in your program, use the Sleep
command like this

Sleep 2 ' inserts a 2ms pause
 
T

Tony B.

Thanks for your response.

I was able to fix the problem and also used your recommendation to give the
process a little breathing room.

Take care and thanks.

Tony B.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top