"iwdu15" <iw****@discussions.microsoft.com> wrote in message
news:94**********************************@microsof t.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(LayoutKind.Sequential)> _
Public Structure LASTINPUTINFO
Public cbSize As Integer
Public dwTime As Integer
End Structure
<DllImport("user32.dll", SetLastError:=True)> _
Public Shared Function GetLastInputInfo(ByRef lii As LASTINPUTINFO) As
Boolean
End Function
Private Const DEFAULT_CHECK_INTERVAL 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.IDisposable.Dispose
[Stop]()
End Sub
Public Sub Start(ByVal maxidletime As Integer)
_maxidletime = maxidletime * 1000
_timer = New Timer(_checkinterval)
_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.ElapsedEventArgs) Handles _timer.Elapsed
Dim lii As New LASTINPUTINFO
lii.cbSize = Marshal.SizeOf(lii)
If GetLastInputInfo(lii) Then
Dim intIdle As Integer = System.Environment.TickCount -
lii.dwTime
If intIdle >= _maxidletime Then
_timer.Stop()
_timer = Nothing
RaiseEvent Idle(Me, New EventArgs)
End If
Else
Debug.WriteLine("IdleWatcher Win32 ERROR: " +
Marshal.GetLastWin32Error().ToString())
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