App Idle Timeout

In CF v1.0 i used OpenNETCF.Windows.Forms.IMessageFilter to detect activity (or lack of) in the app. Does anybody know how to do this in CF2

Here's the code i used...

Imports OpenNETCF.Windows.Forms

Public Class AppIdleTimer

Implements IMessageFilter

'declare timer event and delgate

Delegate Sub TimeoutDelegate()

Public Shared Event AppTimeout As TimeoutDelegate

'declare a system timer

Private m_timer As New Timer

Public Sub New(ByVal TimoutInterval As Integer)

'create an event and degalte to process each event

AddHandler m_timer.Tick, AddressOf TimerProc

'setup timer

m_timer.Interval = TimoutInterval

m_timer.Enabled = True

End Sub

Sub Dispose()

'trash the timer

m_timer.Enabled = False

End Sub

Private Shared Sub TimerProc(ByVal myObject As Object, ByVal myEventArgs As EventArgs)

'fires when app timer ends

RaiseEvent AppTimeout()

End Sub

'this filter receives notification of activity in the app

Public Function PreFilterMessage(ByRef m As Microsoft.WindowsCE.Forms.Message) As Boolean Implements OpenNETCF.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

 

here's the form code

'*******************************************************************************

'Application entry point.

'This sets up the app idle timer. This timer fires when no user input is

'received for the specified period. This will fire a delgate to shut down the

'cdma connection & modem in order to conserve device power.

'*******************************************************************************

Public Shared Sub Main()

Dim config As New Settings((New SettingDefaults).Values)

Dim timeOut As Double

'get timeout interval from app defaults, stored as minutes so convert to milliseconds.

timeOut = CDbl(config.GetString("TimeOut"))

Dim appIdle As New AppIdleTimer(CInt(timeOut * 60000))

Dim frm As New frmMainMenu

'create a handler and assign the delegate to process the timeout events

AddHandler appIdle.AppTimeout, AddressOf frm.AppTimeoutHandler

ApplicationEx.AddMessageFilter(appIdle)

ApplicationEx.Run(frm)

End Sub

'*******************************************************************************

' Delegate used for App idle timer.

'*******************************************************************************

Public Sub AppTimeoutHandler()

Call runNotification()

'Show the Notify Message

'close connection

'toggle device to flight mode

End Sub

 

 

cheers

Paul



Answer this question

App Idle Timeout