Brute Force Programming banner
MIDImage Hangman PushPix Other Programs Delphi Code (previous page) Site Map

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

Methods

Events

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.

Download

© 2004 Brute Force Programming
ALL RIGHTS RESERVED