Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8255605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:34:51+00:00 2026-06-08T01:34:51+00:00

i have a queue that runs every 10 seconds: Private Sub Form1Load(ByVal sender As

  • 0

i have a queue that runs every 10 seconds:

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 & "\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: " & _items.Peek)
                    FileProcessingManager.ProcessFile(_items.Peek)
                    _items.Dequeue()
                End SyncLock
            Loop
        End Sub

    End Class
End Namespace

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?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:34:53+00:00Added an answer on June 8, 2026 at 1:34 am

    In your example code, QueueManager. StartProcessing starts a new thread in which to process the items in the queue. That means it will return immediately, likely before the queue is processed. Then, in the timer elapsed event handler, you restart the timer after a one second delay. So, if the queue takes longer than one second to process, then the timer will indeed get re-enabled before the queue processing is complete. In this situation, I would remove that one second sleep entirely, and have the QueueManager raise an event when it is done. Then your form could just watch for that event, and when it is raised, it could re-enable the timer in the event handler. You will need to do a Me.Invoke to get back on the UI thread first, though, before touching the properties of the timer.

    Public Class Form1
        Private WithEvents _quemanager As New QueueManager()
        Private WithEvents _t As New Timers.Timer(10000)
    
        Private Sub Form1Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            t.Start()
        End Sub
    
        Private Sub _t_Elapsed(ByVal sender As Object, ByVal e As ElapsedEventArgs) Handles _t.Elapsed
            ' disable temporarily
            _t.Stop()
            _quemanager.StartProcessing()
        End Sub
    
        Private Sub _quemanager_ProcessingCompleted() Handles _quemanager.ProcessingCompleted
            _t.Start()
        End Sub
    End Class
    
    Public Class QueueManager
        Private ReadOnly _items As New Queue
        Public Event ProcessingCompleted()
    
        Public Sub StartProcessing()
            '...
        End Sub
    
        Private Sub Process()
            Do
                '...
            Loop
            RaiseEvent ProcessingCompleted()
        End Sub
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WCF service that posts messages to a private, non-transactional MSMQ queue.
I have an object, that on initialization creates a serial GCD queue using dispatch_queue_create
I have a Queue that contains a collection of objects, one of these objects
I have a queue structure that is being used by several pthreads. The threads
I have a single AMQ queue that receives simple messages with string body. Consider
I have something like this in my code: worker.setObject(queue.poll()); I want a queue that
I have a message handler, which consumes from a JMS queue and that sends
I have a class that uses priority queue to display 5 strings in ascending
We have an application that is essentially implementing its own messaging queue. When a
Let's say that I have a module that has a Queue in it. For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.