| |
| Using the Application's OnIdle Event. |
 |
How do I have my application perform work when the computer is idle?
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 TForm .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.
ou can set the boolean variable "done" to true when you want to stop the event handler from executing.
|
|
| Hits/month |
2,500,000+ |
Downloads (Since May 2000) |
7,393,709 |
| Total Files |
6,023 |
| Forum msgs |
7,670 |
| Articles/FAQs |
70+/900+ |
Top Selling Software at Amazon
|