Solved

Check Program idle and timeout

Posted on 2003-11-16
1
522 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create Database on Android via Delphi dbExpress 3 92
Firemonkey DbLookupComboBox equivalent ? 2 48
update joined tables 2 46
Delphi problems to abort a printjob 9 20
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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