title: Thread Sleep and Windows Services
body: <p>I'm working on a Windows Service that's having some issues with <code>Thread.Sleep()</code> so I figured I would try to use a timer instead as this question recommends:</p>
  
  <p><a href="https://stackoverflow.com/questions/998142/using-thread-sleep-in-a-windows-service">Using Thread.Sleep() in a Windows Service</a></p>
  
  <p>Thing is it's not entirely clear to me how one might implement this. I believe this is the way but I just wanted to make sure:</p>
  
  <pre><code>'' Inside The Service Object
  Dim closingGate As System.Threading.AutoResetEvent
  
  Protected Overrides Sub OnStart(ByVal args() As String)
     Dim worker As New Threading.Thread(AddressOf Work)
     worker.Start()
  End Sub
  
  Protected Sub Work()
     Dim Program = New MyProgram()
     closingGate = New System.Threading.AutoResetEvent(False)
     Program.RunService(closingGate)
  End Sub
  
  Protected Overrides Sub OnStop()
     closingGate.Set()
  End Sub
  
  '' Inside My Programs Code:
  Public Sub RunService(closingGate As AutoResetEvent)
     Dim tmr As New Timer
     '' ...and so on
  
     closingGate.WaitOne()
  End Sub
  </code></pre>
  
  <p>Aside from using VB.Net (Kidding, but I'd be using C# if I could.) am I on the right track here? Is this better than using <code>Thread.Sleep()</code>?</p>