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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:09:32+00:00 2026-06-07T16:09:32+00:00

Right now, I’m reading outside application’s memory in a new thread with a infinte

  • 0

Right now, I’m reading outside application’s memory in a new thread with a infinte loop

public void ReadMemory()
{
//read memory
Thread.Sleep(10);
}

Unfortunately, with even sleep of 1 ms, I can get 60-100 loops during 1 minute. Without any sleep, it’s 1000-1500/sec loops but it takes much CPU. I can’t believe there’s nothing I can do with that so Im asking you here :P. CPU usage might be a problem because I’d like to add few more background-working functions in a different threads(or smth else)

is there anything that doesn’t decrease ammount of loops like that with a pause of 10 ms?

  • 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-07T16:09:33+00:00Added an answer on June 7, 2026 at 4:09 pm

    Don’t worry about CPU usage. It’s a nonsensical concept.

    There’s no such thing as “code that runs a little bit”, or “running code slowly to only consume 25% CPU”.

    At the lowest level, it’s a binary thing: your code either runs, consuming 100% of the core it runs on, or it doesn’t, in which case it uses 0% CPU.

    The CPU usage that the OS shows you is a running average.

    So the question you need to ask is not “how do I run my code without using so much CPU”, but the much simpler “does my code run when it shouldn’t be running?” If you want your code to run, then it will, temporarily, at least, use 100% CPU, and there’s nothing wrong with that.

    It’s not really clear what role the Sleep() call plays in your application.
    What are you waiting for? Do you just want a few milliseconds to pass between each iteration? Or are you waiting for some specific event to occur?

    In any case, when you call Sleep(10), you are not suspending your thread for 10 milliseconds. You are suspending it for at least 10 milliseconds. You’re telling the OS to put the thread into a sleep queue now, and once 10 ms have passed, the thread should be considered eligible to execute again. But that still depends on the OS getting around to scheduling your thread, which might take another 10ms (or more, or less, depending on a variety of factors)

    On Windows, Sleep(0) is a special case, which you could experiment with. Instead of actually suspending your thread, it simply tells the OS that the thread is done with its current timeslice, allowing other threads/processes to execute, but without putting your thread to sleep: it’s still eligible to be scheduled the next time a context switch occurs.
    So if the goal is simply to ensure that other threads/processes get a chance to run, calling Sleep(0) might be a way to do it.

    Another way is just to ignore the issue, and trust that the OS knows how to schedule processes (that is a pretty safe assumption. Don’t worry about this unless you’ve actually seen that your other background processes are being starved. They most likely won’t be).

    And finally, of course, you can set thread and process priority, hinting to the OS at which threads it should prefer to schedule. If you give this thread a low priority, it will only be scheduled when no higher-prioritized thread is available, ensuring you won’t starve out other threads.

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

Sidebar

Related Questions

Right now I am using sqlite within a ios application, and I want to
Right now any new UIViewController added to my storyboard needs to have a class
Right now I have an application that loads a bunch of thumbnail images into
Right now I'm using OleDbDataAdapter objDataReader = new OleDbDataAdapter(); objDataReader.SelectCommand = myCommand; objDataReader.Fill(myDataTable); But
Right now I have to create a new physical file in eclipse android for
Right now, I'm particularly interested in reading the data from MP3 files (ID3 tags?),
Right now, I have an enum like this: public enum ReferenceType { Language =
Right now I have an upload field while uploads files to the server. The
Right now, I have: RewriteRule ^([^/\.]+)?$ index.php?id=$1 [L] to match any username at the
Right now when I run this it keeps clicking on the same button every

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.