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

  • SEARCH
  • Home
  • 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 647123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:41:17+00:00 2026-05-13T21:41:17+00:00

I’m simulating some threading in a Windows Service, and the Thread.Start routine for each

  • 0

I’m simulating some threading in a Windows Service, and the Thread.Start routine for each of my threads points directly to the following:

Private WithEvents CheckForOrdersTimer As System.Threading.Timer

Private Sub timerCheckForContracts_Tick(ByVal stateInfo As Object)
    ' Ticks every 5 seconds, then spawns threads until we're at our max
    Do

        If ThreadCollection.Count < MaxThreads Then

            Dim t As New Threading.Thread(AddressOf SomeThreadingCode()
            ThreadCollection.Add(t)
            t.Start()

        End If
    Loop

End Sub


Private Sub SomeThreadingCode()
    Do
        Thread.Sleep(1000)
        If Me.ThreadsShouldContinue = False Then  ' Global thread-stopper
            Exit Sub
        End If
        If (New Random).NextDouble > 0.8 Then  ' On average, wait 5 seconds
            Exit Do
        End If

    Loop

    ' Remove this thread from the main collection
    ThreadCollection.Remove(Thread.CurrentThread)

End Sub

Pretty simple – the threads aren’t even doing anything yet, but with more than two threads running at the same time, my processor (Core 2 Duo 2.4 w/ 4GB) gets pegged and Windows gets really sluggish. According to what I’ve read, Thread.Sleep shouldn’t be consuming any resources at all while it waits, but it may as well be running in a tight timing loop.

Can anybody explain to me what’s going on here?

EDIT: Per the requests, I’ve expanded the amount of code I’m using. I was initially doing some database work before spawning each thread, but I’ve removed it and the processor maximization still occurs with just the code here (and, of course, the OnStart method for the Windows Service.

  • 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-05-13T21:41:17+00:00Added an answer on May 13, 2026 at 9:41 pm

    timerCheckForContracts_Tick is running an infinite loop, and never goes to sleep, etc. Even if you are “ticking” it every 5 seconds, there is no code within the loop to prevent it from consuming CPU cycles, forever checking:

        If ThreadCollection.Count < MaxThreads Then
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 382k
  • Answers 382k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer wp_insert_post and wp_publish_post May 14, 2026 at 10:26 pm
  • Editorial Team
    Editorial Team added an answer My guess is you are hitting the 'locale restriction' listed… May 14, 2026 at 10:26 pm
  • Editorial Team
    Editorial Team added an answer Thans for you answer, but that's my point i don't… May 14, 2026 at 10:26 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.