I am trying to figure out an best way of shutdown my application in an X amount of time if it is inactive, but i am having trouble of figure it out. If anyone knows, please help. I am truly appreciated.
It's been a while since I did this and I've only done it in Visual FoxPro, so it might lose a little in the translation (if all of the things are possible in VB - I have only done a couple of projects in VB - so I don't have it all figure out yet), but it'll give you the general idea and you can flesh it out from there if you like.
First have a variable that you can stuff the date & time into.
When the user uses the keyboard or the mouse, place the current date/time PLUS the desired idle time (you called it X above) shutdown into the varible.
Have a timeer on each form that will check this variable and compare it to the current date/time. If the date/time in the variable has passed, shut down. IF not - then do nothing.
I shut down the VFP forms by calling the click event on the Exit/Close buttons on the form from the timer event for example:
If you place a timer on your form and set a variable to the time that the form loads you could do something like this
Private Sub Timer1_Timer()
If DateDiff("n", tStart, Now()) > 1 Then
myShutdown
End If
End Sub
The above could uses the variable tStart As Date that is set to Now() when the form loads. The Timer1 Interval is set to 100 ms and after 1 minute the myShutdown Sub is called. All you have to do is refresh the tStart variable when an activity occurs (ie mouse click etc). Hope this helps. Anything is possible, the problem is I only have one lifetime.
That's what I currently have it work right now but Since I have so many forms i dont want to have a timer on every form I Just want know if there is way that I can just Have this shutdown my application in my main forms and still be able to keep track all the child forms Activities.
Do you want the entire application to shut-down after a certain amount of time?
If yes, put the timer only on the MDI Form and when your time amount has ran out do a "End". But, when there is activity on any of the sub-forms you will need to reset your timer (I don't know of any way around that).
If no, a timer will be nessary on each individual form.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.