Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Win API / December 2007



Tip: Looking for answers? Try searching our database.

Cap CPU Utilization

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Spawn666948 - 30 Nov 2007 21:38 GMT
Is there a way to cap the CPU utilization for a particular process?

Example:  for certain processes, I don't want them going above 10%.

The reason I'm trying to do this is because even when I set the
processes to Low Priority, they still seem to hog the cpu.  Opening
apps as simple is Notepad takes forever.
Michael C - 01 Dec 2007 11:42 GMT
> Is there a way to cap the CPU utilization for a particular process?
>
[quoted text clipped - 3 lines]
> processes to Low Priority, they still seem to hog the cpu.  Opening
> apps as simple is Notepad takes forever.

One way I can think of doing this is to time x number of loops. If those
loops take 0.1 seconds then do a sleep for 0.9 seconds. That will give 10%
cpu usage approx.
Spawn666948 - 01 Dec 2007 19:20 GMT
> One way I can think of doing this is to time x number of loops. If those
> loops take 0.1 seconds then do a sleep for 0.9 seconds. That will give 10%
> cpu usage approx.

Can you explain what you mean by "time x number of loops"?  Thanks.
Michael C - 01 Dec 2007 22:59 GMT
>> One way I can think of doing this is to time x number of loops. If those
>> loops take 0.1 seconds then do a sleep for 0.9 seconds. That will give
>> 10%
>> cpu usage approx.
>
> Can you explain what you mean by "time x number of loops"?  Thanks.

You have a process that does something repetitive I presume? (it's very
difficult to write any code that takes a long time if something doesn't
repeat :-). Anyway, code would be something like this. GetTickCount and
sleep are API calls.

dim i as long
dim t1 as long, t2 as long
t1 = GetTickCount
for x = 1 to 100000000000000000
  i = i + 1
  if i = 1000 then
       t2 = gettickcount
       t1 = t2 - t1
       sleep t1 * 9
       i = 0
       t1 = t2
  end if
next
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.