title: vb.net queue that runs every 10 seconds
body: <p>i have a queue that runs every 10 seconds:</p>
  
  <pre><code>Private Sub Form1Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
  
          Dim t As New Timers.Timer(10000)
          AddHandler t.Elapsed, New ElapsedEventHandler(AddressOf Elapsed)
          t.Start()
      End Sub
  
      Private Sub Elapsed(ByVal sender As Object, ByVal e As ElapsedEventArgs)
  
          Dim timer1 As Timers.Timer = DirectCast(sender, Timers.Timer)
  
          Try
              ' disable temporarily
              timer1.Stop()
              _quemanager.StartProcessing()
              Thread.Sleep(1000)
          Finally
              ' make sure that the handler is always reenables
              timer1.Start()
          End Try
      End Sub
  
  Namespace Managers
  
      Public Class QueueManager
  
          Private ReadOnly _items As New Queue
  
          Public Sub StartProcessing()
  
              For Each x In From i In File.GetAllAccountFolders() From x1 In File.CheckFolderForFiles(i &amp; "\In") Select x1
                  _items.Enqueue(x)
              Next
  
              Dim t1 As New Threading.Thread(AddressOf Process)
  
              t1.Start()
          End Sub
  
          Private Sub Process()
              Do
                  SyncLock _items.SyncRoot
                      If _items.Count = 0 Then
                          'No more items.
                          Logger.Log("QueueManager", "Process", "No Items In Queue")
                          Exit Do
                      End If
                      Logger.Log("QueueManager", "Process", "Processing File: " &amp; _items.Peek)
                      FileProcessingManager.ProcessFile(_items.Peek)
                      _items.Dequeue()
                  End SyncLock
              Loop
          End Sub
  
      End Class
  End Namespace
  </code></pre>
  
  <p>the logic behind this should be that the timer elapses every 10 seconds stops the timer runs the queue then when the queue has finished it should then start the timer again am i rite in thinking this? and theres no way the timer could restart its self untill the queue has finished?</p>
  
  <p>Thanks</p>