"iwdu15" <iw****@discuss ions.microsoft. com> wrote in message
news:94******** *************** ***********@mic rosoft.com...
how can i tell if my system has gone idle? then how can i execute a
command
accordingly? thnks
Hi,
You can use class i wrote for my project:
--
Imports System.Timers
Imports System.Runtime. InteropServices
Public Class IdleWatcher
Implements IDisposable
<StructLayout(L ayoutKind.Seque ntial)> _
Public Structure LASTINPUTINFO
Public cbSize As Integer
Public dwTime As Integer
End Structure
<DllImport("use r32.dll", SetLastError:=T rue)> _
Public Shared Function GetLastInputInf o(ByRef lii As LASTINPUTINFO) As
Boolean
End Function
Private Const DEFAULT_CHECK_I NTERVAL As Integer = 500
Private _checkinterval As Integer
Private _maxidletime As Integer
Private WithEvents _timer As Timer = Nothing
Public Event Idle(ByVal sender As Object, ByVal e As EventArgs)
Sub New()
Me.New(DEFAULT_ CHECK_INTERVAL)
End Sub
Sub New(ByVal checkinterval As Integer)
_checkinterval = checkinterval
End Sub
Public Sub Dispose() Implements System.IDisposa ble.Dispose
[Stop]()
End Sub
Public Sub Start(ByVal maxidletime As Integer)
_maxidletime = maxidletime * 1000
_timer = New Timer(_checkint erval)
_timer.Start()
End Sub
Public Sub [Stop]()
If Not _timer Is Nothing Then
_timer.Stop()
_timer.Dispose( )
_timer = Nothing
End If
End Sub
Private Sub _timer_Elapsed( ByVal sender As Object, ByVal e As
System.Timers.E lapsedEventArgs ) Handles _timer.Elapsed
Dim lii As New LASTINPUTINFO
lii.cbSize = Marshal.SizeOf( lii)
If GetLastInputInf o(lii) Then
Dim intIdle As Integer = System.Environm ent.TickCount -
lii.dwTime
If intIdle >= _maxidletime Then
_timer.Stop()
_timer = Nothing
RaiseEvent Idle(Me, New EventArgs)
End If
Else
Debug.WriteLine ("IdleWatche r Win32 ERROR: " +
Marshal.GetLast Win32Error().To String())
End If
lii = Nothing
End Sub
End Class
--
i hope this is what you are looking for
Regards,
Josip Habjan
URL:
http://www.habjansoftware.com