Click here to Skip to main content
15,891,905 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Question about Thread.Sleep() Pin
Tristan Rhodes7-May-07 11:14
Tristan Rhodes7-May-07 11:14 
AnswerRe: Question about Thread.Sleep() Pin
simsem7-May-07 20:55
simsem7-May-07 20:55 
GeneralRe: Question about Thread.Sleep() Pin
Tristan Rhodes8-May-07 2:51
Tristan Rhodes8-May-07 2:51 
GeneralRe: Question about Thread.Sleep() Pin
Colin Angus Mackay10-May-07 2:14
Colin Angus Mackay10-May-07 2:14 
GeneralRe: Question about Thread.Sleep() Pin
Tristan Rhodes10-May-07 2:35
Tristan Rhodes10-May-07 2:35 
GeneralRe: Question about Thread.Sleep() Pin
Colin Angus Mackay10-May-07 3:42
Colin Angus Mackay10-May-07 3:42 
GeneralRe: Question about Thread.Sleep() Pin
Tristan Rhodes10-May-07 4:29
Tristan Rhodes10-May-07 4:29 
GeneralRe: Question about Thread.Sleep() Pin
Colin Angus Mackay10-May-07 5:54
Colin Angus Mackay10-May-07 5:54 
Tristan Rhodes wrote:
Clearly there is going to be a wait for the database response to process and return, and i'd like other threads to use that time instead of the current thread.


The thread will block while it waits for the network response. Just as it will block if it is waiting for a disk read and so on. While the thread is blocked the OS will switch to the next available highest priority non-blocked thread. The OS will not attempt to run blocked threads. So blocked threads will not take up processor time.


Tristan Rhodes wrote:
the thread is locked and not shared leading to a performance hit with lots of concurrent request


Locking is a different issue.

Locking relates to resources. For example, if you are performing an update on an object that takes several lines of code the OS can interupt the operation and swap in a different thread (or the other thread may be running on a separate processor or core). Either way, while you are making the update you want to lock out any other changes so that your object remains in a consistent state. When you lock the object you block other threads from locking it at the same time.

If a thread attempts to lock an object that is already locked its will be blocked, the OS will move on to the next thread (the highest priority non-blocked thread). When the first thread releases the lock the second thread can then aquire it. For obvious reasons a lock should be aquired and released as quickly as possible, you don't want to block other threads too long.


Tristan Rhodes wrote:
a thread.sleep would enable it to be freed up and process other requests whilst waiting for the DB to response


The thread will block anyway while waiting for the result set to return. You are just implementing what is already taken care of in the OS - and less efficiently because you continually wake up and perform a check then go back to sleep again. The synchronous database request will just wait (i.e. It will be blocked) until something is available or the operation times out.

Tristan Rhodes wrote:
Where have i gone wrong?


By the looks of it confusing locking with blocking. I hope this has explained enough that you've got a better handle on the situation.



Upcoming events:
* Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services...

Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton


My website

GeneralRe: Question about Thread.Sleep() Pin
Tristan Rhodes10-May-07 6:25
Tristan Rhodes10-May-07 6:25 
QuestionHow do you halt a program while waiting for a KeyDown? Pin
vonLochow6-May-07 23:28
vonLochow6-May-07 23:28 
AnswerRe: How do you halt a program while waiting for a KeyDown? Pin
Arun.Immanuel7-May-07 1:30
Arun.Immanuel7-May-07 1:30 
QuestionWindows Workflow Rules question Pin
abc8766-May-07 21:21
abc8766-May-07 21:21 
Questionneed help with remoting incoming event handler Pin
neodeaths6-May-07 16:34
neodeaths6-May-07 16:34 
AnswerRe: need help with remoting incoming event handler Pin
Wilco07-May-07 4:32
Wilco07-May-07 4:32 
QuestionProblem With Custom PaperSize In .NET Pin
AmirAlilou4-May-07 21:56
AmirAlilou4-May-07 21:56 
Questionhow do i set the values for my class variable for remoting? Pin
neodeaths3-May-07 23:22
neodeaths3-May-07 23:22 
QuestionCode convertor tool in Vb .net Pin
Balagurunathan S3-May-07 21:51
Balagurunathan S3-May-07 21:51 
AnswerRe: Code convertor tool in Vb .net Pin
Blumen3-May-07 23:02
Blumen3-May-07 23:02 
GeneralRe: Code convertor tool in Vb .net Pin
Balagurunathan S4-May-07 0:03
Balagurunathan S4-May-07 0:03 
GeneralRe: Code convertor tool in Vb .net Pin
Christian Graus6-May-07 17:58
protectorChristian Graus6-May-07 17:58 
AnswerRe: Code convertor tool in Vb .net Pin
Blumen7-May-07 5:48
Blumen7-May-07 5:48 
AnswerRe: Code convertor tool in Vb .net Pin
Dave Kreskowiak4-May-07 2:33
mveDave Kreskowiak4-May-07 2:33 
GeneralRe: Code convertor tool in Vb .net Pin
Blumen8-May-07 2:14
Blumen8-May-07 2:14 
GeneralRe: Code convertor tool in Vb .net Pin
Dave Kreskowiak8-May-07 3:46
mveDave Kreskowiak8-May-07 3:46 
AnswerRe: Code convertor tool in Vb .net Pin
Paul Conrad4-May-07 14:00
professionalPaul Conrad4-May-07 14:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.