Solved

Check Program idle and timeout

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

896 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now