所以我有以下代码块:
var sw = new Stopwatch();
sw.Start();
while (sw.Elapsed.Seconds<10)
{
System.Threading.Thread.Sleep(50);
Console.WriteLine(sw.Elapsed.Milliseconds.ToString() + " ms");
}
sw.Stop();
在输出中我有
50 ms
101 ms
151 ms
202 ms
253 ms
304 ms
355 ms
405 ms
456 ms
507 ms
558 ms
608 ms
659 ms
710 ms
761 ms
812 ms
862 ms
913 ms
964 ms
15 ms
65 ms
116 ms
167 ms
218 ms
为什么它每 1000 毫秒重置一次?我需要等待 10 秒,但我无法使用Thread.Sleep(10000);
,因为我使用的这个第 3 方库也在休眠,我需要它在那段时间做一些事情。