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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
AlanRank #669 · 3.6K reputationPosted Jan 25, 2008, 5:46 AM EST
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.
Eric13 reputationPosted Jan 25, 2008, 5:50 AM EST
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