Better Sleep

using System; using System.Diagnostics; public static class BetterSleep { static readonly Stopwatch sw = new Stopwatch(); public static void Sleep(long ms) { sw.Start(); while (sw.ElapsedMilliseconds < ms) { /* wait */ } sw.Reset(); } }
System.Threading.Thread.Sleep(int milliseconds) guarantees to sleep for AT LEAST the specified milliseconds. This class sleeps the exact milliseconds. But keep in mind that this should be called from a single thread application!

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.