> 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