'inactivity timer code
Dim inActivity As New Stopwatch
Protected Overrides Sub WndProc(ByRef m As Message)
'Listen for operating system messages to the application. If the form to expire is moved, mousemove detected, keydown detected it will stay open
'When no message is sent from the OS within 30 seconds the form will expire.
resetActivity()
MyBase.WndProc(m)
End Sub
Private Sub loadevent(ByVal sender As Object, ByVal e As System.EventArgs)
resetActivity()
formtimeout.Interval = 1 * 1000 'check every 1 second for new messages from the OS
formtimeout.Start()
End Sub
Public Sub resetActivity()
inActivity.Reset()
inActivity.Start()
End Sub
Private ReadOnly maxInactivity As New TimeSpan(0, 0, 15) '15 second timeout - integer (Hours, Minutes, Seconds) in your case (0 hours, 0 minutes, 30 seconds)
Private Sub form_timeout(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles formtimeout.Tick
If inActivity.Elapsed > maxInactivity Then
Dim Formhome As New Form1
Formhome.Show()
Me.Close()
End If
End Sub
Thanks in advance for any assistance on this if anyone has a better way of doing this.

New Topic/Question
Reply



MultiQuote







|