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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:01:26+00:00 2026-06-08T22:01:26+00:00

Is there any way to limit the number of processors that the ThreadPool object

  • 0

Is there any way to limit the number of processors that the ThreadPool object will use? According to the docs, “You cannot set the number of worker threads or the number of I/O completion threads to a number smaller than the number of processors in the computer.”

So how can I limit my program to not consume all the processors?

  • 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-08T22:01:28+00:00Added an answer on June 8, 2026 at 10:01 pm

    After some experiments, I think I have just the thing. I’ve noticed that the ThreadPool considers the number of processors in the system as the number of processors available to the current process. This can work to your advantage.

    I have 4 cores in my CPU. Trying to call SetMaxThreads with 2:

    ThreadPool.SetMaxThreads(2, 2);
    

    fails since I have 4 cores and so the numbers remain at their initial values (1023 and 1000 for my system).

    However, like I said initially, the ThreadPool only considers the number of processors available to the process, which I can manage using Process.ProcessorAffinity. Doing this:

    Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(3);  
    

    limits the available processors to the first two cores (since 3 = 11 in binary). Calling SetMaxThreads again:

    ThreadPool.SetMaxThreads(2, 2);
    

    should work like a charm (at least it did for me). Just make sure to use the affinity setting right at program start-up!

    Of course, I would not encourage this hack, since anyway your process will be stuck with a limited number of cores for the entire duration of its execution.

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

Sidebar

Related Questions

Is there any way to limit a number of characters that are loaded using
Is there any way I can set a formatter on models that will convert
In HLSL, is there any way to limit the number of constant registers that
Is there any way to use Zend_Filter_Encrypt with large files, without rising memory limit
Is there any way to limit the number of attempt to gain access to
Is there any way around to limit number of workers in celery ? I
1) Is there any way to limit the scope of an Envers audit trail?
I just want to check if there is any easy way to limit zooming.
Is there any way to use Google's API to retrieve a user's current zipcode
There are a set of common pages that I want to use in multiple

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.