Title | Make a program close itself if it has been inactive for too long |
Keywords | inactive, security, close |
Categories | Software Engineering |
|
|
Create a variable to keep track of the timeout time. Create a routine that resets this value to some time in the future. This example sets the time for 15 seconds from now but a real application would set this to something longer such as 15 minutes.
|
|
Private m_TimeoutTime As Date
' Set the timeout for 15 seconds from now.
Private Sub SetTimeout()
m_TimeoutTime = DateAdd("s", 15, Date + Time)
lblTimeout.Caption = m_TimeoutTime
End Sub
|
|
Invoke this routine whenever the user does something that should keep the program active.
|
|
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As _
Integer)
SetTimeout
End Sub
|
|
Finally, use a timer to see if it's time to quit the application.
|
|
' See if it's time to quit.
Private Sub tmrTimeout_Timer()
If Date + Time > m_TimeoutTime Then Unload Me
End Sub
|
|
The program should perform any necessary clean up and shutdown chores before ending the application.
You could also make it take other less drastic actions such as locking itself or displaying a warning dialog with its own timer that unloads the application in 30 seconds if the user doesn't respond.
|
|
|
|