[DUG] CPU usage

John Bird johnkbird at paradise.net.nz
Fri Aug 21 12:33:14 NZST 2009


There is a reason for that not being easy:

1 - there is no reliable way I have found to detect when the screensaver has 
actually started - if you know one please pass it on!

There however is a neat way to find if the computer has been idle for a 
while  (meaning no keyboard or mouse)
 Doesn't measure current CPU of course.   But actually currently not doing 
interactive stuff is probably good enough for my purposes - so oddly enough 
thanks for reminding me of another way I could do it.

This below combined with reading the registry for screensaver settings would 
give an idea when the screensaver should start, but there seems to be no 
easy way to be sure it actually has.

function SecondsIdle: DWord;
var
   liInfo: TLastInputInfo;
begin
   liInfo.cbSize := SizeOf(TLastInputInfo) ;
   GetLastInputInfo(liInfo) ;
   Result := (GetTickCount - liInfo.dwTime) DIV 1000;
end;


John


> Hi John,
>
> Wait for the screensaver to kick in ? :)
>
> Cheers,
>
> Pieter
> ----- Original Message ----- 
> From: "John Bird" <johnkbird at paradise.net.nz>
> To: "NZ Borland Developers Group - Delphi List" <delphi at delphi.org.nz>
> Sent: Thursday, August 20, 2009 15:58
> Subject: [DUG] CPU usage
>
>
>> Is there a simple way to find simple measure of current CPU usage?
>>
>> Reason - have some housekeeping tasks that I would prefer to not run if
>> the
>> computer is loaded at the moment, so an easy way to check before starting
>> it
>> would be great.
>>
>> Does not have to be too precise for my case, basically something that
>> answers "is the computer really busy or mainly idle at the moment?"
>>
>> Here is a couple of examples I found -  wondering if there is a simpler
>> call
>> for XP/Vista/Windows 7
>> http://www.swissdelphicenter.ch/torry/showcode.php?id=969
>> http://www.vbforums.com/showthread.php?t=343530
>>
>> John
>>
>>
>> _______________________________________________
>> NZ Borland Developers Group - Delphi mailing list
>> Post: delphi at delphi.org.nz
>> Admin: http://delphi.org.nz/mailman/listinfo/delphi
>> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
>> unsubscribe
>>
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at delphi.org.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject: 
> unsubscribe 




More information about the Delphi mailing list