Thread Sleep Problem - Micro Seconds

  • Thread starter Thread starter Darth
  • Start date Start date
D

Darth

Hi,

How does one make a thread sleep for some "microseconds" in C# ?

TIA,
Darth
 
Darth said:
Hi,

How does one make a thread sleep for some "microseconds" in C# ?

TIA,
Darth

You can't put a thread asleep for a precise time period is impossible in Windows, nor can
you put a thread asleep for anything less than a couple of milliseconds.
A thread that calls Thread.Sleep with a value less than the thread quantum (10 - xx msec.)
simply gives up his thread quantum until scheduled again, which can be after a couple of
microseconds but also after a few seconds.


Willy.
 
jibesh said:
try

Thread.Sleep(1/1000); --> sleep for one microseconds

Except that 1/1000 is 0. Even if you changed it to 1.0/1000, the
parameter to Thread.Sleep is an int, not a double. The overload which
takes a TimeSpan ignores fractional milliseconds, according to the
documentation.

There is no way of telling a thread to sleep for a given number of
microseconds - Thread.SpinWait will wait for short times, but is almost
never useful.
 
Darth said:
How does one make a thread sleep for some "microseconds" in C# ?

Generally, if you need microsecond resolution, Windows (any flavour) is not
the right OS.

That being said, in old-fashioned Windows programming (no .NET or C#), I
have used a multimedia timer. The advantage is that the call-back function
is called the moment the timer triggers and not whenever Windows sees fit.
The disadvantage is that you need to assure data protection yourself, it is
probably only possible to use this in unmanaged code and you still get
millisecond resolution only.

Ebbe
 

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