How to do sleep in microsecond
-
There is no way from the .NET framework to make a thread sleep for less than a millisecond. You can call Thread.Sleep(0) which will simply cause the process to switch contexts and let another thread run for a moment before returning and processing the current thread.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: And in this corner, the Party of Allah The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
Maybe the StopWatch class can help you.
StopWatch watch = StopWatch.StartNew();
while (watch.ElapsedTicks < someValue)
{
}somevalue has to be computed from
Stopwatch.Frequency
to reflect the wanted amount of microseconds. Should be some easy math but I'm too lazy and also want to leave some coding for you :) -- modified at 16:26 Monday 14th August, 2006 Just an annotation: This way your thread doesn't really sleep but actively waits for time to go by, so this isn't really good practice and shouldn't be used often.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
It can't be done. The Windows platform doesn't have programmable access to any hardware timers with that kind of resolution.
Dave Kreskowiak Microsoft MVP - Visual Basic
-
Thread.Sleep(100). This worked for me before
-
Thread.Sleep(100). This worked for me before
A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane
-
Thread.Sleep(100). This worked for me before
1 millisecond = 1000 microseconds...
Dave Kreskowiak Microsoft MVP - Visual Basic
-
It can't be done. The Windows platform doesn't have programmable access to any hardware timers with that kind of resolution.
Dave Kreskowiak Microsoft MVP - Visual Basic
I was wondering when someone would realise this :rolleyes:
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed
-
Althought the QueryPerformanceCounter function does have a resolution of 1 microsecond, you cannot sleep a process that accurately. The best your going to do is 1 millisecond, and even then, the resolution can vary by 10-15 milliseconds due to Windows being a shared system.
Dave Kreskowiak Microsoft MVP - Visual Basic