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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:44:03+00:00 2026-06-06T01:44:03+00:00

I’ve got a queue (actually 3 different queues but I don’t believe that will

  • 0

I’ve got a queue (actually 3 different queues but I don’t believe that will make a difference). The queue contains discrete units of work.

I have a QueueManager which spawns a new thread and returns. The new thread looks at the queue, gets a piece of work and then spawns a new thread to process it.

I obviously want a limit on the number of concurrent threads and don’t see any reason not to reuse a thread once it’s finished the job.

Some of the jobs will take a while to run (minutes/hours) and I’ve read that the ThreadPool is not a good option for anything that takes more than a few seconds.

Effectively, I want to implement the ThreadPool but with a little more control.

So… What’s the standard, best-practice way to achieve this?

It seems I need to (assuming the queue length > MaxThreadCount)

  • Create new jobs until I hit MaxThreadCount
  • Wait until any thread completes
  • Get the next job from the queue and assign it to the thread
  • Repeat
  • If the queue empties, sleep for a length of time and then re-check

(The queue in this case is in a database so no event when items are added – I assume I’ll just have to poll)

A lot of the jobs involve retrieving pages from remote sites/APIs, often repeatedly. As such, I believe I’d benefit from having considerably more threads than cores (as most of them will be waiting for the network). As such, I don’t believe WaitHandle is appropriate as it has a 64-Thread limit.

This is obviously a pretty common pattern so I assume there must be a well-established way of implementing it?

If someone could point me at a good example, the would be excellent.

  • 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-06T01:44:05+00:00Added an answer on June 6, 2026 at 1:44 am

    Use the TPL (Task Parallel Library). It’s designed for exactly this purpose.

    http://msdn.microsoft.com/en-us/library/dd460717.aspx

    Specifically, it sounds like you should create a TaskFactory with a TaskScheduler instance whose MaximumConcurrencyLevel has been set to the number of threads that you want. Then instead of putting your work items in a queue, call TaskFactory.StartNew. It will handle the queueing of work for you.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I need to clean up various Word 'smart' characters in user input, including but

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.