Solved

Check Program idle and timeout

Posted on 2003-11-16
1
519 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
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, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

11 Experts available now in Live!

Get 1:1 Help Now