Hi, 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.