ello
Many people have asked this question, and I have tried the examples, but am still unable to get the result I want.
I am writing a windows form-based application (a staff database), which PR will be using to manage staff movements within the company. There will be lots of sensitive information that needs protecting from prying eyes.
I am writing the application in VB.NET Academic Version (2003).
I have written the "hibernate" function which sends the application to the system tray when the user selects "Hibernate" from the main menu. When they right click on the applications icon in the system tray, they can restore the application to the screen, but they must login first. This much is written.
However, if the user leaves their desk for 5 minutes (proving no interaction - even GetFocus() !), the system needs to execute the hibernate function, hence 'autohibernate'. This period of time should be able to be reduced or expanded to even 30 minutes or 30 seconds!
I need the code that fires the sub 'Hibernate' when the user hasn't been using the system for given period of time.
I have tried the Application.Idle, but this wont tell me when there is interaction, which is equally as important. If, at any time, the application is not firing messages, then the application is seen as idle. However, at any point between checks the system could be non-idle, in which case I would need to be able to reset a counter which defines the whole period of time that I want the system to be certain that there is no interaction for.
So, I am assuming that every second, the system checks the idle status (how do I check this to be non-idle). If it is idle, then the counter is increased. If it is non-idle, then the counter is reset. If the counter reaches its time (total time/1second), then the timeout has been reached.
I do not wish to have to write the mousemove,mouseclick,keydown (etc) events for every object in my application as this will get messy and unreliable.
I tried the following code as a class, then the code that follows it is incorporated into sub main () where the system runs the actual application, the problem is that the prefiltermessage is never executed?? Why??
Imports System.Windows.Forms
Public Class clsAppIdleTimer
Implements System.Windows.Forms.IMessageFilter
Delegate Sub TimeoutDelegate()
Public Shared Event AppTimeout As TimeoutDelegate
Private m_timer As New Timer
Public Sub New(ByVal TimoutInterval As Integer)
AddHandler m_timer.Tick, AddressOf TimerProc
m_timer.Interval = TimoutInterval
m_timer.Enabled = True
End Sub
Sub Dispose()
m_timer.Enabled = False
End Sub
Private Shared Sub TimerProc(ByVal myObject As Object, ByVal myEventArgs As EventArgs)
RaiseEvent AppTimeout()
End Sub
Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean _
Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
Select Case m.Msg
Case &H200 To &H209, &H100 To &H108 ' mouse, key events
m_timer.Enabled = False
m_timer.Enabled = True
End Select
End Function
End Class
... and now the sub main, which exists in a global module ...
Public Sub Main()
'we have the main Sub Main Code Here!
' idle.CreateDelegate(system.Type.Get