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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:28:32+00:00 2026-05-12T10:28:32+00:00

I have an application that grabs a snapshot of another desktop. This process is

  • 0

I have an application that grabs a snapshot of another desktop. This process is placed and run asynchronously in a separate backgroundworker thread. Tiny mockup of the DoWork event is:

private void GrabImage_DoWork(object sender, DoWorkEventArgs e)
{
 /*Grab the image..*/
 System.Threading.Thread.Sleep(10)
}

Currently there was placed a thread.sleep(10) and I am just wondering whether such a small sleep will actually render the performance poor due to constant additional unneeded context switches.

Let me know if the question requires further explanation.
Cheers,

EDIT:
Decided to throw a bunch of more context in to help focus on a specific answer.

Issues brought up
Q: Is this the only background thread currently running?
A: No. There is in fact a few backgroundworker threads as well as a thread which queues up multiple threads using the .NET Threadpool class. Therefore the sleep was originally placed into the code for the thought of allowing a context switch to occur for these other threads.
However I am lead to believe that anyways the OS is time sliced so that I’m sure without the sleep the other threads will get a chance to execute?

Q: Is this background worker constantly running?
A: The application provides an interface to interact with the desktop with a toggle button to display the background image.
Therefore the backgroundworker can essentially be off or constantly churning if the button is toggled.

I hope the overall question doesn’t seem overall unimportant to performance. I am trying to find a good balance between performance and usability.

  • 1 1 Answer
  • 1 View
  • 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-12T10:28:32+00:00Added an answer on May 12, 2026 at 10:28 am

    The sleep will potentially cause extra context switching, since it will allow other threads to execute within your process.

    However, it sounds like you have a single background worker thread. If that’s the case, you probably are going to get context switching anyways. This tends to happen any time background workers reports progress (since they’re invoking across threads) as well. With one, I doubt you’ll notice the performance hit involved, although the only way to tell for sure would be to profile your application.

    My bigger question would be: Why are you adding this Sleep in here in the first place, especially if it’s something you’re worried about. Typically, you’d add a sleep in here specifically to allow other threads to work, which often results in a context switch. If you’re doing this by design, then it’s not something to worry about. If you don’t need this Sleep, on the other hand, there’s no reason to include it.


    Edit: Here are some specifics in reply to your edit:

    Q: Is this the only background thread currently running? A: No. There is in fact a few backgroundworker threads as well as a thread which queues up multiple threads using the .NET Threadpool class. Therefore the sleep was originally placed into the code for the thought of allowing a context switch to occur for these other threads. However I am lead to believe that anyways the OS is time sliced so that I’m sure without the sleep the other threads will get a chance to execute?

    The OS will time slice, but (by default) this thread will have a default priority. It should, in theory, get as much of the processor time as your main thread and other threads running. You don’t have to sleep, but there are times when this is advantageous (see below).

    Q: Is this background worker constantly running? A: The application provides an interface to interact with the desktop with a toggle button to display the background image. Therefore the backgroundworker can essentially be off or constantly churning if the button is toggled.

    If the worker thread is going to be sitting in a loop and just constantly eating CPU, it’s usually advantageous to add some mechanism to prevent it from using up the entire CPU core (unless you need real-time performance in that thread). A small sleep (although Sleep(0) works just as well for this) is an easy option. However, it’s often better, if the algorithm makes sense for this, to put some type of WaitHandle in place so you’re only working as needed. This really depends on the algorithm.

    Since I am already using the Threadpool class, is to queue this workload as well onto the threadpool class instead of a sepearte backgroundworker.

    The BackgroundWorker class uses a ThreadPool thread, so there isn’t a real advantage to doing this. BackgroundWorker makes it much simpler to work against a UI thread, however, so if you’re displaying your progress on the UI, it’s probably easier to do this with a BW, as you’re doing now.

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

Sidebar

Related Questions

I have an application that goes like this F5 load balancer - IHS(a&b) -
I have a Galaxy Note device and I wrote an application that grabs uimages
We currently have an application (Windows service) that connects to another of our applications
I have created a small SIFT application that grabs the keypoints and saves it
I have this application that has dynamic language switching built in. Based on the
I have application that makes different queries with different results so the caching in
I have application that is connecting to the DB and if I enter incorrect
I have application that is up more than 3 days. I can see in
I have application that brings response via Ajax and creates 5-20 new jQuery click
I am building a Rails application that contains Developer s who have Application s.

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.