How to wait

  • Thread starter Thread starter Alan T
  • Start date Start date
If you just want your application to pause for two seconds you can use

System.Threading.Thread.Sleep(2000);

This will cause the current thread to wait for 2 seconds before
resuming where it left off
 
Just add to others - SpinWait to wait without relinquishing the CPU

--
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
Michael Nemtsev said:
Just add to others - SpinWait to wait without relinquishing the CPU
EEK, spin for 2 seconds! You should never do that. First off, you should never spin on a
mono cpu box, second you should never spin for anything longer than the time taken by a
transition into the kernel and back.

Willy.
 
I completely agree but lacking any other further information about
exactly what the application does and the context of the wait...
 
I completely agree but lacking any other further information about
exactly what the application does and the context of the wait...

Hmm... not sure what you mean here, you know the difference between a Sleep and a SpinWait
do you?
You should never call SpinWait for as long as 2 seconds whatever the context.

Willy.
 
Sorry Willy - I had misread your post. But I dont recall saying you
should spinwait for 2 seconds? Instead of picking up on my mistakes
maybe you could use your time more productively to give an answer to
Alans initial question

For the benifit of anyone else -
Sleep - will relinquish control of the thread for the number of
milliseconds denoted by the parameter -technicaly it is removed from
consideration by the thread scheduler for that length of time
SpinWait - will effectively lock the current thread into a tight loop
for a specified number of itterations. Generally not recommended and is
only genuinely useful in a small number situations

:-)
Nick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top