Solved

Check Program idle and timeout

Posted on 2003-11-16
1
527 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month4 days, 11 hours left to enroll

636 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