473,322 Members | 1,232 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Thread Sleep Problem - Micro Seconds

Hi,

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

TIA,
Darth

Feb 10 '07 #1
6 17185

try

Thread.Sleep(1/1000); --sleep for one microseconds
"Darth" <lo**********@gmail.comwrote in message
news:11**********************@v45g2000cwv.googlegr oups.com...
Hi,

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

TIA,
Darth

Feb 10 '07 #2
"Darth" <lo**********@gmail.comwrote in message
news:11**********************@v45g2000cwv.googlegr oups.com...
Hi,

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

TIA,
Darth

Feb 10 '07 #3
"Darth" <lo**********@gmail.comwrote in message
news:11**********************@v45g2000cwv.googlegr oups.com...
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.

Feb 10 '07 #4
jibesh <ji*******@gmail.comwrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 10 '07 #5
if you want to 'pause' for a known about of time, why not try a Timer
object, it has the ability to fire events for a time based on milliseconds.

check out:

http://msdn.microsoft.com/library/de...ClassTopic.asp

HTH

Ollie Riches

"Darth" <lo**********@gmail.comwrote in message
news:11**********************@v45g2000cwv.googlegr oups.com...
Hi,

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

TIA,
Darth

Feb 10 '07 #6
Darth wrote:
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
Feb 12 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: news.microsoft.com | last post by:
Hi, Currently I have a thread thats spinning and doing a Thread.Sleep(someTime). I was thinking of changing this to Thread.Sleep(Timeout.Infinite); then when I have actual data in a...
8
by: Cider123 | last post by:
I ran into a situation where my Window Service had to process 100,000+ files, when I first noticed I needed to tweak various routines. Everything runs fine, but here's what I ran into: In the...
3
by: Stephen Miller | last post by:
I have an ASP.Net application that sends a NetworkStream to a .Net Service, which has a TcpListener listening on a port for the ASP.Net client. When it receives a request it creates a new thread...
3
by: al | last post by:
Greetings, I have a simple page with this code in Page_Load event(vb.net): Response.Buffer=True Response.write("begin test") Response.Flush()
9
by: Chris Dunaway | last post by:
According to the docs, calling Thread.Sleep(0) causes the thread to be "suspended to allow other waiting threads to execute." What happens if I call Thread.Sleep(500)? Do other threads not get a...
1
by: Fernando Rodríguez | last post by:
Hi, I have a class that descends from threading.Thread. One method should block the thread during x seconds and then call another method. How can I do this?
14
by: Joe | last post by:
Does anyone know the difference, in practical terms, between Thread.Sleep (10000) and Thread.CurrentThread.Join (10000)?? The MSDN says that with Join, standard COM and SendMessage pumping...
9
by: Andy | last post by:
Hi, I have some things that act in a typical producer consumer fashion. When they have work to do, I want them doing that, but if there's no work, I'm currently using Thread.Sleep to cause...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.