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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:27:32+00:00 2026-06-02T03:27:32+00:00

Is there a way to tell the thread pool mananger to only have x

  • 0

Is there a way to tell the thread pool mananger to only have x number of threads invoking a specific method or group of methods?

I have an application where I use thread pool worker threads all over the place, and it works swimmingly; one of the tasks I consign to the worker threads is a web service call, however, and it will reject more than 5 concurrent requests. I don’t want to limit the thread pool to 5 threads, because many other things use the threads and can handle a great many more.

Is there a way to “compartmentalize” a thread pool to say “you will have a maximum of x threads active doing this particular thing at any point in time, but the rest of you threads can go do other stuff”?

  • 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-02T03:27:34+00:00Added an answer on June 2, 2026 at 3:27 am

    Create another threadpool and SetMaxThreads(5) – it’s the easiest way.

    OK, you can’t do it with Threadpool class.

    Just so I’m not downvoted:

    public abstract class Task {
        public EventHandler FonComplete;
        public ThreadPool myPool;
        protected int param;
        public Exception error;
        public Task(int inParam, EventHandler OnDone) { param = inParam; FonComplete = OnDone; }
        public abstract void run();
    };
    
    
    public class PoolThread{
    private
        BlockingCollection<Task> FinQueue;
    public
        PoolThread(BlockingCollection<Task> inQueue)
        {
           FinQueue=inQueue; 
        }
        Task inMess;
        public void run(){
            while(true){
                inMess=FinQueue.Take();
                if(inMess==null) return;
                try
                {
                    inMess.run();
                    inMess.error = null;
                }
                catch (Exception e)
                {
                    inMess.error = e;
                }
                inMess.FonComplete(inMess, null);
            }
        }
    };
    
    public class ThreadPool {
        int FthreadCount;
        BlockingCollection<Task> queue;
        void startThread(){
                PoolThread thisPoolThread=new PoolThread(queue);
                Thread thisThread=new Thread(new ThreadStart(thisPoolThread.run));
                thisThread.Priority = ThreadPriority.BelowNormal;
                thisThread.IsBackground = true;
                thisThread.Start();
        }
        void SetThreadCount(int newCount){
            while(FthreadCount<newCount){startThread();};
            while(FthreadCount>newCount){
                queue.Add(default(Task));
                FthreadCount--;
            };
        }
        public ThreadPool(int initThreads){
            queue=new BlockingCollection<Task>();
            for(FthreadCount=0;FthreadCount<initThreads;FthreadCount++) startThread();
        }
        public int threadCount{
            get{return FthreadCount;}
            set
            {
                while (FthreadCount < value) {
                    startThread();
                    FthreadCount++;
                };
                while (FthreadCount > value)
                {
                    queue.Add(default(Task));
                    FthreadCount--;
                }
            }
        }
    
        public void submit(Task task){
            task.myPool=this;
            queue.Add(task);
        }
    };
    
    }
    

    It’s not like the ‘real’ System.Threading.Threadpool, but it is a threadpool with a fixed number of threads

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

Sidebar

Related Questions

Is there a way to tell the php complier that I want a specific
I have a MouseListener Thread where this method is called each time there is
Is there a way to tell if a thread has exited normally or because
Can anyone tell me if there's a way to run a thread and give
Is there any way to prevent the doInBackground method/thread of an AsyncTask from starting
Is there a way to wait all threads in executor pool when pause button
Given a System.Timers.Timer, is there a way from the main thread to tell if
Is there any way to tell GCC to not initialize a particular global array
Is there any way to tell db4o to call class default constructor while activating
Is there a way to tell excel to not display non-significant series in a

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.