Welcome! Log In Create A New Profile

Advanced

End WD23 application after time of inactivity.

Posted by AadG 
End WD23 application after time of inactivity.
December 30, 2018 12:10PM
Hi all,

Is there a way to end a WD23 application after a certain time of inactivity ?
I want workstations that are left unattended (evening, night) to end the application
automatically.

Thanks for any help or hints.

Best regards,

Aad
Re: End WD23 application after time of inactivity.
December 30, 2018 03:30PM
Hi Aad,

I'd start with

[help.windev.com]

Maybe, you can persuade it to to do an EndProgram() too ?

Kind regards,
Guenter Predl
office@windev.at
Re: End WD23 application after time of inactivity.
December 30, 2018 03:45PM
Hi Guenther,

I was already looking at LockAppTimeOut() but I want to END not LOCK. smiling smiley
Thanks for the tip though.

Best regards,

Aad
Re: End WD23 application after time of inactivity.
December 30, 2018 05:15PM
LockAppTimeout triggers a AAF window WindevLockApp.wdw. Putting Endprogramm() in the "Focus gain" section does the trick.
You have to import WindevLockApp first in your application. from the Presetsmap (AAF)

Aad
Re: End WD23 application after time of inactivity.
December 30, 2018 05:19PM
Hi Aad,

I imagined something like that!
Great solution!

Kind regards,
Guenter Predl
office@windev.at
Re: End WD23 application after time of inactivity.
December 30, 2018 05:45PM
Thanks Guenter
Re: End WD23 application after time of inactivity.
December 31, 2018 11:32AM
Hello Guenter,

I tried this and has a pitfall. If the app is in the background any code of the window does not fire until it gets focus.

DW
Re: End WD23 application after time of inactivity.
December 31, 2018 03:34PM
Hi DW,

I have no problems with starting other programs after I start my WD appl.
I discovered something else. The application does not end but is send to the taskbar, so it is still there.
When I click on the taskbar icon the window WindevLockApp appears (only that) and when I click
"Close the application", then it really shuts down and is removed from the taskmanager.
I tried to use ExecuteProcess(Button,Trtclick), but this only works, when the program is activated
from the tasbar.

I'don't know how to solve this.

Best egards,

Aad
Re: End WD23 application after time of inactivity.
December 31, 2018 08:01PM
Hello Aad,

My issue is that my users never will logout on their own. They stay connected to the DB from days at a time I was hoping to be able to close the connection when the timeout happens then start a timer that will close the app 10 minutes later. This is not possible with the lock functions because the lock window does not fire any code until after focus gain from the taskbar.

I will have to go another way.

DW
JP
Re: End WD23 application after time of inactivity.
January 01, 2019 11:56AM
Aad,

We force users out of our systems at 2am for various maintenance routines we want to run. We do this using a timer that runs in its own thread. It uses the WD automatic timer function which we setup on application start and checks every 10 minutes. It actually checks for 2 things; the time being 2am and also for a special file which I can manually create to force users to logoff on-demand at anytime when I need them to logoff.

In the timer routine you could do some code such as;

1) Store the current mouse X,Y position

2) If the current mouse position is different from the last stored position then reset an time variable to current time

3) if current mouse position is the same as the previous mouse position then test the internal time variable and see if more than NN minutes have passed. i.e. you are testing to see if the user has moved the mouse at all in the last NN minutes i.e. is the user active on the system

4) In addition you could test for last key pressed and see if that has changed.

5) If neither the last key nor the mouse position has changed for over NN minutes then probably the user is no longer active and you can shutdown the application ... and/or ...

6) ... you could popup a message saying the system will exit in 10 minutes. If that dialog is also not answered then really the user has "left the building" smiling smiley and you can shut the app down.

Happy New Year.

JP
Re: End WD23 application after time of inactivity.
January 01, 2019 03:26PM
Hi JP,

Happy new year to U2. Thanks for your input. I solved my problem
very easily with the procedural integrated timers. I did not know that they existed.
I made 2 procedures. One is checking the CursorPosition every minute. The other is checking the
CursorPos every 60 minutes. When the values are the same after an hour, the program ends,
That's all.

Thanks again.

Best regards,

Aad
Re: End WD23 application after time of inactivity.
January 01, 2019 06:42PM
Hello JP,

Have a question on this:

4) In addition you could test for last key pressed and see if that has changed.

How would one trap last keystroke?

Can this be done on a global level or on each window open?

I was playing around with putting code on the Keydown/Keypressed process of a window and did not work like expected.

DW
JP
Re: End WD23 application after time of inactivity.
January 01, 2019 10:11PM
DW

In Visual FoxPro there was a function called LastKey() which I could use to determine whatever the last key the user pressed was. In WinDev there does not seem to be the equivalent function but I'm sure the VFP function just calls a Windows API. I shall try and find more info on the API and let you know.

JP
gga
Re: End WD23 application after time of inactivity.
January 02, 2019 02:01AM
This was programmed in a fit of exasperation after a user left my program open before leaving for the day one too many times. I fully expected to have to give it more thought but this simple solution seems to have worked for the past 11 months.
I put a timed procedure in my Global Procedures: (gnQuitTime is initialized in my program initialization and in my case is set to 2300)

PROCEDURE End_Program_Timer()
IF Val(Left(Now,4)) > gnQuitTime THEN
InfoWithTimeout(5000,"Closing program")
EndProgram()
END
Re: End WD23 application after time of inactivity.
January 05, 2019 05:09PM
Hello All,

I think this is the best solution that I found to trap inactivity of a app.

In the Project code:
//This will trap the user using the mouse or the keyboard in all the windows of the app
//Make sure you have this for the constants
EXTERN "WinConst.WL"

//Create a int that will hold the seconds
gnTimeOutClock is int

//Trap the events of the user
Event(EV_ResetTime, "*.*", WM_LBUTTONUP)
Event(EV_ResetTime, "*.*", WM_RBUTTONUP)
Event(EV_ResetTime, "*.*", WM_MBUTTONUP)
Event(EV_ResetTime, "*.*", WM_KEYUP)
//Start the timer (Automatic timer every second in its own thread)
EV_MoveTime()

Create a global procedure to move the "gnTimeOutClock" 1 per second.
//// Automatic Procedure:
// The procedure is run manually, during a call in the code
// It will be run in a thread (without having to call ThreadExecute), without using HFSQL
// It will be repeated in loop, with a timeout set to 1 second between each call
EV_MoveTime()

gnTimeOutClock++

//Create a global function to rest the timer
PROCEDURE EV_ResetTime()

gnTimeOutClock=0

Now the rest is up to you on how you want to handle the closing of the app.
For me I created a edit control called Idle Time that sits in the main window of the app to show how long since the last activity. I created another timer that checks to see if the app has been idle for 15 Minutes then I popup a window that gives them 5 more minutes then close the app.

Hope this helps

Dennis W



Edited 2 time(s). Last edit at 01/05/2019 05:16PM by cabinetman.
JP
Re: End WD23 application after time of inactivity.
January 06, 2019 02:12PM
@DennisW

This a neat solution! but I dont think it covers one situation we face which is that a user can open up charts and reports in our app and just monitor them without interacting with our app. They are just watching live charts and reports. Which means they might not click in our app or use the keyboard in our app. So I would add the mouse X,Y position test to see if the user has moved the mouse which indicates whether they are actually at the computer vs. having left the computer on but no longer there.



Edited 2 time(s). Last edit at 01/06/2019 03:58PM by JP.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: