title: VB.NET: How to know time for which system is idle?
body: <p>I'm making an application in which I'm implementing <b>auto-monitor turn off</b> when system is idle, i.e. when user is not interacting with the system. </p>
  
  <p>I found a link: <a href="http://www.codeproject.com/KB/system/SystemIdleTimerComponent.aspx" rel="nofollow">http://www.codeproject.com/KB/system/SystemIdleTimerComponent.aspx</a></p>
  
  <p>it does provides the componenent to know when system is idle. But when I include:</p>
  
  <pre><code>Public WM_SYSCOMMAND As Integer = &amp;H112
  Public SC_MONITORPOWER As Integer = &amp;Hf170
  
  &lt;DllImport("user32.dll")&gt; _
  Private Shared Function SendMessage(hWnd As Integer, hMsg As Integer, wParam As Integer, lParam As Integer) As Integer
  End Function
  
  Private Sub button1_Click(sender As Object, e As System.EventArgs)
      SendMessage(Me.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, 2)
  End Sub
  </code></pre>
  
  <p>It shows this error: <b>Cross-thread operation not valid: Control 'Form1' accessed from a thread other than the thread it was created on.</b></p>