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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:08:56+00:00 2026-05-24T12:08:56+00:00

I have question on controlling the amount of concurrent threads I want running. Let

  • 0

I have question on controlling the amount of concurrent threads I want running. Let me explain with what I currently do: For example

 var myItems = getItems(); // is just some generic list

 // cycle through the mails, picking 10 at a time
 int index = 0;
 int itemsToTake = myItems.Count >= 10 ? 10 : myItems.Count;
 while (index < myItems.Count)
 {
     var itemRange = myItems.GetRange(index, itemsToTake);
     AutoResetEvent[] handles = new AutoResetEvent[itemsToTake];

     for (int i = 0; i < itemRange.Count; i++)
     {
         var item = itemRange[i];
         handles[i] = new AutoResetEvent(false);

         // set up the thread
         ThreadPool.QueueUserWorkItem(processItems, new Item_Thread(handles[i], item));
     }

    // wait for all the threads to finish
    WaitHandle.WaitAll(handles);

    // update the index
    index += itemsToTake;
    // make sure that the next batch of items to get is within range
    itemsToTake = (itemsToTake + index < myItems.Count) ? itemsToTake : myItems.Count -index;

This is a path that I currently take. However I do not like it at all. I know I can ‘manage’ the thread pool itself, but I have heard it is not advisable to do so. So what is the alternative? The semaphore class?

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-05-24T12:08:58+00:00Added an answer on May 24, 2026 at 12:08 pm

    Don’t use THE treadpool, get another one (just look for google, there are half a dozen implementations out) and manage that yourself.

    Managing THE treadpool is not advisable as a lot of internal workings may go ther, managing your OWN threadpool instance is totally ok.

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

Sidebar

Related Questions

Question I want to load a nib file at Server to an application running
I just have a quick question. I am running through an array of images
I have question about parsing in Html helper : I have sth like: @foreach
I have question. I have some app on facebook and getting this error Fatal
I have question about clean thory in Python. When: @decorator_func def func(bla, alba): pass
I have question about XSLT1.0. The task is to write out in HTML all
I have Question and QuestionTypes. In Question table there is a foreign key that
I have question i.e how can i select a previous div CODE:- if($i >
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have question regarding the use of function parameters. In the past I have

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.