Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I know Thread.Sleep(number) is looked down upon as it locks the UI thread however reading a C# threading guide it uses Thread.Sleep(0); to give control to another thread. In some of past code there was annoying waits for things that was caused by the Threading were freed up via a Thread.Sleep(100) will Thread.Sleep(0); free up things with out a wait while the form does nothing!
Opions please!

Glenn
Posted
Updated 25-Jan-12 23:58pm
v2
Comments
glennPattonWork3 26-Jan-12 11:25am    
is the same thing for Thread.SpinWait() I can't seem to find anything on it other than MSDN, from I can gather from a cursory read is it holds the thread like Thread.Sleep but not. Too much coding not enough coffee!!

See Here[^] 5th Para down.

But yeah, generally, try to avoid them.
 
Share this answer
 
v2
Comments
CPallini 26-Jan-12 7:36am    
Good link, my 5.
You better do asynchronous calls where the endcall invokes a delegate that brings data / image / etc to the gui thread.
With asynchronity the GUI thread doesn't lock and the processing goes on. It gives better responsiveness to the system. You can create an abort call because buttons keep working....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900