Главная страница | назад





Article #17665: Using the Application's OnIdle Event.

 Question and Answer Database
FAQ2665D.txt Using the Application's OnIdle Event.
Category :VCL
Platform :All
Product :All 32 bit
Question:
How do I have my application perform work when the computer
is idle?
Answer:
You can create an OnIdle event to be called whenever your
application is waiting for messages to be processed. Simply
declare the event handler procedure in the private section
of the forms declaration:
{ Private declarations }
procedure IdleEventHandler(Sender: TObject; var Done: Boolean);
In then implementation section, define the procedure:
procedure TForm1.IdleEventHandler(Sender: TObject;
var Done: Boolean);
begin
{Do a small bit of work here}
Done := false;
end;
Then assign the Application's OnIdle event to point to your
new procedure(You may do this whereever you like, but a good
place would be the Forms OnCreate method):
Application.OnIdle := IdleEventHandler;
OnIdle is called only once, as the application transitions
into an idle state. It is not called continuiously unless
Done is set to False If Done is False, WaitMessage is not
called. Applications that set Done to False consume an
inordinate amount of CPU time that affects overall system
performance.
You can set the boolean variable "done" to true when you want
to stop the event handler from executing.
7/16/98 4:31:28 PM

Last Modified: 01-SEP-99