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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:23:36+00:00 2026-06-09T06:23:36+00:00

I have a polling loop in C# that needs to poll every 100 microseconds

  • 0

I have a polling loop in C# that needs to poll every 100 microseconds on average < EDIT> (given of course that there is no excessive preemptive thread context switch carried out by Windows due to core shortage) < /EDIT>.

As there is no time for a reschedule, Sleep(1) will not do.

So I decided to dedicate a thread (and in practise, a core when setting affinity) and use a Thread.SpinWait for a set of cycles for each iteration. While this works fine, it eats an unnecessary amount of power. The 100 microseconds would be plenty enough for the CPU to pause (while not enough to have the thread temporary removed from the scheduler as the Windows time-slice would be way to long).

Instead, I was thinking of using the Intel PAUSE instruction but I’m not sure it will trigger the Intel CPU to suspend the hardware thread. Intel claims it preserves power and should be used in a spin loop, but as the pause is as long a as 100 microsecond, I really want the core to go into a C1 mode sleep.

Any ideas?

Edit: I’m polling a third party API, so there is no synchronization event to block on.

  • 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-09T06:23:38+00:00Added an answer on June 9, 2026 at 6:23 am

    Naturally using synchronization primitives and timers is a preferred way to go to avoid CPU/power-hungry busy wait. However, if you need to poll so frequently – there’s no way to achieve this by conventional means, at least in user mode.

    One simple thing that you may do is to include a pause CPU instruction within your loop. In MSVC it’s implemented by an intrinsic YieldProcessor() method.

    Beyond this – probably in kernel-mode programming only. There you may use a high-precision multimedia timer.

    Edit:

    About SetWaitableTimer. This may be an option. Unlike “traditional” Win32 waiting functions (such as Sleep, WaitForSingleObject and etc.) it uses a high-precision timeout as a parameter.

    However user-mode timers are asynchronous in nature. Let’s assume the timer becomes active with high precision (thpigh this is not obvious, “traditional” Win32 waiting functions are accurate up to tick quanta, order of tens of milliseconds). After the timer becomes active – it releases the appropriate waiting thread(s). But thread scheduler doesn’t have to attach this thread to the execution immediately – it may wait for the next time slice. Or even delay the thread execution more if there are concurrent threads.

    In conclusion: the idea seems worth trying. But I won’t be surprised if this is more-or-less equivalent to using Sleep.

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

Sidebar

Related Questions

I have created a WCF method that runs an infinite loop, polling every 5
I have a basic mochiweb polling loop that looks like the following, except it
Per Apple’s Polling Versus Run-Loop Scheduling: [ hasSpace/BytesAvailable ] can mean that there is
I have an object that is updated from a polling loop on a thread.
I have a project that involves polling a hardware switch each update and converting
In my application, I want to have a polling loop which blocks on a
I have a while loop running that is returning values from a MYSQL table.
I have a loop pulling information from my database. How can I add a
I have a WPF test app for evaluating event-based serial port communication (vs. polling
Let's say I have two windows services running. One service is 'Polling' - it

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.