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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:51:24+00:00 2026-06-10T00:51:24+00:00

I know that setting thread priority is a bit of a taboo subject on

  • 0

I know that setting thread priority is a bit of a taboo subject on stack overflow but I am convinced that my application is a good candidate for increased priority. To justify that, I have explained the context below. The question now is HOW to do that effectively?

The application is .NET 4 (C#) console application that executes a complex algorithm with an execution time of about five hours. The algorithm is not memory-intensive at all, just processor intensive. It does number crunching and does NOT perform any disk I/O, database connectivity, network connectivity, etc. The output of the application is a just ONE number that it writes to the console at the end. In other words, the algorithm is completely self-contained and has no dependencies.

The application runs on its own dedicated 16 core 64 bit machine running Windows Server with far more free RAM than it requires (8GB). By dedicated I mean the server has been procured to run this application EXCLUSIVELY.

I have already optimized the code as much as I could with extensive profiling, fancy math shortcuts and bit twiddling hacks.

Here is the overall structure in pseudocode:

public static void Main ()
{
    Process.GetCurrentProcess().PriorityBoostEnabled = true;
    Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime;

    // Of course this only affects the main thread rather than child threads.
    Thread.CurrentThread.Priority = ThreadPriority.Highest;

    BigInteger seed = SomeExtremelyLargeNumber; // Millions of digits.

    // The following loop takes [seed] and processes some numbers.
    result1 = Parallel.For(/* With thread-static variables. */);

    while (true) // Main loop that cannot be parallelized.
    {
        // Processes result1.
        result2 = Parallel.For(/* With thread-static variables. */);

        // Processes result2.
        result1 = Parallel.For(/* With thread-static variables. */);

        if (result1 == criteria)
            break;

        // Note: This loop does not need to sleep or care about system responsiveness.
    }
}

Now based on the thread priority related questions on SO, I gather that anything using ThreadPool should not be messed around with in terms of priority. So If I need to switch to manual threads, so be it.

Question:

  • How should I change the above code to manual threading to benefit from increased thread priority (not using thread pool etc.)?
  • Will setting priority to highest on all child threads even help? I mean will the child threads just be fighting with each other or will that give them an edge over external OS tasks?
  • Considering there are 16 cores, should I be running 16 or 15 threads? Is there a general guideline to this?
  • Will setting process priority to real-time help as well?
  • 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-10T00:51:26+00:00Added an answer on June 10, 2026 at 12:51 am

    With such an app, I would expect changing the priorities to make 0% difference to the overall runtime. If you’re already maxed out on CPU use with all 16 cores at 100% doing real work, there’s not much more you can do.

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

Sidebar

Related Questions

I know about Allow Triggers to Fire Others server setting that allows the action
I want to know if Netbeans has some option or setting that will allow
I know that Phonegap has an event for back button, but it's only available
I know that this sort of question has been asked here before, but still
I know that Java have its own garbage collection, but sometimes I want to
I wanted to know if this was thread safe/ good practice. My IOC is
I have a thread in a Java web application that causes a java.lang.OutOfMemoryError: Java
I'm learning C. I'm writing an application with multiple threads; I know that when
I have a class library that has settings within an app.config. I know that
I know that if port 443 is open that means the remote host supports

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.