Consultor Eletrônico



Kbase P168380: How to detect a period of no activity in a .NETUI based application?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   01/04/2011
Status: Unverified

GOAL:

How to detect a period of no activity in a .NETUI based application?

GOAL:

How can I detect that the user has not done anything in my .NET based application?

FACT(s) (Environment):

OpenEdge 10.2x
Windows

FIX:

To implement an application level timeout which will shut down the application after a specified period of time with no activity you can implement the following for the main .NET Form:

First, add an instance of a Timer control to the form, set the appropriate tick value and enable it then add code similar to the following to the Timer's Tick event:

method private void timer1_Tick( input sender as System.Object, input e as System.EventArgs ):
if etime >= 15000 then
do:
message 'Going to Timeout Now' view-as alert-box.
quit.
end.
end method.

Second, add an override of the WndProc method to the source code for the .NET Form (with at least the code shown below):

method override protected void WndProc( input-output m as System.Windows.Forms.Message ):
super:WndProc(input-output m).

/*
private const int WM_KEYFIRST = 0x0100; 256
private const int WM_KEYLAST = 0x0108; 264
private const int WM_MOUSEFIRST = 0x0200; 512
private const int WM_MOUSELAST = 0x0209; 521
*/

if (m:Msg >= 256 and m:Msg <= 264) or (m:Msg >= 512 and m:Msg <= 521) then
do:
/* a keyboard or mouse event of some kind was generated so now you */
/* must reset whatever kind of timer mechanism you want to use */
etime(true).
end.
end method.

This code will see all mouse and keyboard events then reset ETIME whenever one is encountered. The tick even checks ETIME and if 15 seconds have elapsed with no mouse or keyboard events it will shutdown the application.

This code has been tested in OpenEdge 10.2B with a single .NET Form and a single .NET Form which in turns runs a persistent .w and leaves it up and running. This code has not been tested with either a .NET Dialog or a .w style dialog box so further testing by the programmer needs to be done for those scenarios. Because both types of dialogs use their own WAIT-FOR it is expected that this high level code would not work and that the same type of code would need to be implemented on a dialog by dialog basis.