TAppKiller
Writing applications in a corporate environment, I've noticed that some people start apps when they come in to work in the morning and leave the apps running all day long, whether they are actively using them or not.
This isn't necessarily a problem...usually...most of the time.
But when I've just finished writing a newer version of the app, and would like to place it on the server, I can't because the file is in use.
Hence, TAppKiller, a component that terminates an application after a set time of no activity.
Properties
- Active
-determines whether the application will terminate on timeout. This does not start the timeout clock. Use the Start procedure to do that. default : False - CheckKeys
-if True, will start the timeout each time a key is pressed. default : True - CheckMouse
-if True, will start the timeout each time a mouse buttonis clicked. default : True - IdleLimit
-the number of minutes to allow the application to sit idle before it terminates. default : 60 minutes - WarnAt
-the number of minutes before the timeout period ends to fire the OnWarn event. default : 5 minutes
Methods
- Start
-sets Active to True, and starts the timeout clock - Stop
-sets Active to False. Start must be used to restart the timeout process.
Events
- OnStart
-fires when the timeout process is started. - OnWarn
-fires when the WarnAt time is reached.
Usage
Drop the component on the main form. In the form's OnCreate or OnShow event, use the [AppKiller].Start procedure to begin the countdown.
AppKiller will monitor the main form and all child forms for keyboard and mouse activity, restarting the countdown after each keypress or mouseclick.
Caveats
AppKiller was written in/for Delphi 4. It should work in D2-D6, but you will probably have to change some things, like Cardinal to LongInt or Integer, for example.
Use the Stop procedure to stop AppKiller during length processing. For instance, if the user starts an SQL that may run longer than the timeout period, stop the timeout, then restart it after the SQL finishes. (Setting Active to False has the same effect)
AppKiller uses Application.OnMessage to check the Mouse
and Keyboard activity. If your own application also uses OnMessage,
then AppKiller's OnMessage process will not run.
In this case, use the Start procedure to restart the clock,
(probably in your own OnMessage event, something like this:
procedure TmyForm.MyAppMessage(var Msg: TMsg; var Handled: Boolean);
begin
Handled := False;
IF AppKiller1.CheckKeys AND (Msg.message = WM_KEYDOWN) THEN
AppKiller1.Start;
IF AppKiller1.CheckMouse THEN
CASE Msg.message OF
WM_LBUTTONDOWN,
WM_MBUTTONDOWN,
WM_RBUTTONDOWN : AppKiller1.Start;
END;
{Do your message handling here}
end;
AppKiller uses Application.Terminate to end the application, so anything that might prevent the termination of the application under normal circumstances will also prevent it here.
The timing is not exact. Setting the timeout to 60 minutes will usually mean the application terminates at 61 minutes or so.
© 2004 Brute Force Programming
ALL RIGHTS RESERVED
