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

The Archive Base Latest Questions

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

I have time-critical piece of code in my app. I made the thread which

  • 0

I have time-critical piece of code in my app. I made the thread which runs it Highest priority – that’s the most I could do.

Is there any suggestions on how to make part of the code run in this thread to be interrupted as few times as possible (less context switch occurred) ?

The code is not complicated. I replaced all the method calls with inlined code and I don’t use anything of high level (like no LINQ). The most of operations are arithmetic. There is only one comparison of strings (I am thinking of ways how to rid of it). Half of maths are with ints and half with doubles.

The code is x86 .NET 4 C#. Runs on single Xenon X3450 W2008R2. Single app server.

(Unfortunately data is coming from 3d party API which doesn’t support x64 (hate it!))

I’d appreciate grown-up discussion with experienced developers.

P.S. The server has no paging file so hard page faults wont happen either (no unwanted IO operations).

  • 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-15T12:27:09+00:00Added an answer on May 15, 2026 at 12:27 pm

    The only thing you need to worry about in terms of context switches, is blocking your thread. So there should be no problem with using LINQ (that is, LINQ-to-objects, obviously LINQ-to-SQL or whatever would involve blocking!). Any sort of arithmetic or calling methods and so on will also not block the thread and so have no impact on context switches.

    The other thing that affects context switching is, as you noted, priority. But not just thread priority, also your process’s priority. You can use SetPriorityClass to increase your process’s priority to ABOVE_NORMAL_PRIORITY_CLASS (I wouldn’t bother putting it higher than that) and then set your thread’s priority to Above Normal as well.

    However, in general, priorities are really only useful when it’s a matter of timing (that is, making sure your process responds to external input (network, user input, disk I/O) as fast as possible). It will actually have very little impact on your thread’s actual throughput, unless you have other processes that are also CPU-bound running at the same time. But if that’s the case, then fiddling with priorities is not going to be a viable long-term solution anyway. This is because you’ll find that by setting one of the processes to a higher priority, it’ll completely starve the other processes and they’ll never run.

    So anyway, I would carefully consider things before adjusting thread and process priorities. And, as always, test, test, test!

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

Sidebar

Related Questions

I have 2 time values which have the type datetime.time . I want to
Our users have created MS-Excel spreadsheets which over time have evolved into fairly complex
I have a real-time embedded app with the major cycle running at 10KHz. It
I have a new web app that is packaged as a WAR as part
I have a time represented as the number of seconds elapsed since midnight, January
Every time I have to estimate time for a project (or review someone else's
Every time I have to build a form with a DateTime field I try
I have imported a time series with dates of the following format: test =
I always seem to have a hard time starting a new Firefox extension. Can
For a long time i have tried to work out the best way to

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.