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 136093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:53:38+00:00 2026-05-11T06:53:38+00:00

In the main loop of a worker thread that has to poll to know

  • 0

In the main loop of a worker thread that has to poll to know if there’s work to do, I let it sleep in order to not busy-wait. How do I determine a good length for sleeping? E. g. if I wake up every millisecond, it’s probably useless to sleep at all. If I wake up every ten minutes, it might make the app look unresponsive (depending on what the thread is doing).

I’ve heard before what cadrian says below, that a human user won’t notice timespans around 100 ms, but what about approaching it from the machine side? How small can the interval get before it starts to get wasteful?

I guess, it boils down to a more general (i. e. platform-independent) version of this question.

EDIT: Of course, the question should always be rephrased first as ‘How can I change this to the event pattern instead of polling’, but let’s assume for now that I can’t or don’t want to.

  • 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. 2026-05-11T06:53:39+00:00Added an answer on May 11, 2026 at 6:53 am

    Sometimes polling is the answer.

    However, how often it polls depends on what the thread is doing, so make it configurable.

    We have threads that check for email. They can check external mail boxes, we only check the mailboxes every thirty seconds or so (but it’s configurable). Each check is a call over the web, calling every second or 10th of a second would hammer the network, 30 seconds is ok, and it doesn’t matter if the email isn’t processed THE MOMENT it lands in the in box (however some customer sites check every 5 mintues).

    We have other threads that poll for files in a folder, and/or for new requests added to a table in the database. These poll for work every 1 to 5 seconds (depending on what they’re doing).

    Now regardless of how long you wait between polling, we don’t let any of our threads sleep for longer than a second. The reason being, if you try to stop a windows service that has a thread sleeping for 60 seconds, you could be waiting 60 seconds before the service stops.

    If you need to bring a machine down in a hurry, a Rip Van Winkle thread will really twist your mellon.

    So, have your polling intervals as far apart as you need, but don’t sleep for much longer than a second.

    Hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.