Solved

Check Program idle and timeout

Posted on 2003-11-16
1
524 Views
Last Modified: 2010-04-05
I need to develop the program that has the timeout feature.
If the program idle for 1 hrs, it will automatic close
How can i check the program idle for 1 hrs ?
I had think about timer but is it affect
the program performance and normal
operation ?

Any Suggestion
Thx !
0
Comment
Question by:expert256256
1 Comment
 
LVL 5

Accepted Solution

by:
snehanshu earned 125 total points
ID: 9761527
expert256256,
I haven't tried this before but you could do this (Hope it helps):
If your question is "how to determine whether or not the application was idle for 1 hour", then IMHO, you could track the application's messages and reset the timer if the message was a mouse or keyboard event.
Perhaps something like this (With more ORs added in the AppMessage procedure):

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure AppMessage(var Msg: TMsg; var Handled: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
//  Check message type: the list here can be expanded to Mouse button down etc.
  Application.OnIdle
  If (Msg.message = WM_MOUSEFIRST) OR (Msg.message = WM_MOUSELAST)
    OR (Msg.message = WM_KEYFIRST) OR (Msg.message = WM_KEYLAST) Then
  begin
    Timer1.Enabled := False;
    Timer1.Enabled := True;
  end
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Timer1.Interval := (1000 * 60*60);
  Timer1.Enabled := True;
  Application.OnMessage := AppMessage;//Monoitor all messages to the application
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := False;//Idle for too long: terminate
  Application.Terminate;
end;

end.

Perhaps something could be done using Application.OnIdle etc. but I haven't used those before.
The above example is for "Application Idle", for "system Idle" you could use hooks or journal records.
HTH,
...Snehanshu
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question