for some reason i need to ping every 0.01milli-second, but thread.sleep() or timer wont be able to do it, since sleep() only takes int, which means 1 milli-second or 0, and timer only takes 0 or 15.6247 milli-seconds.
any help? thanks~
for some reason i need to ping every 0.01milli-second, but thread.sleep() or timer wont be able to do it, since sleep() only takes int, which means 1 milli-second or 0, and timer only takes 0 or 15.6247 milli-seconds.
any help? thanks~
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
EricPosted Jan 25, 2008, 10:50 AM
Thanks lot! I am using 2.0, but I never know that class.
The second way is what I am trying now, but it does not work on different machines. orz
AlanPosted Jan 25, 2008, 10:46 AM
If you have .NET 2.0 or later, then you should certainly be able to get down to a resolution of 10,000 nanoseconds (1/100,000th of a second) using the Stopwatch class:
http://msdn2.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx
Otherwise, I'd use the age old method of a 'do nothing' for loop. Try and work out how many iterations could be done in 1 millisecond on your machine and then scale it down accordingly.