C# Stopwatch 延时
using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading; class Program { static void Main(string[] args) { Stopwatch stopWatch = new Stopwatch(); long times1 =0; long DelayTime = 1000; while (true) { stopWatch.Start(); Console.WriteLine("DoSomeThing..."); Console.WriteLine("DoSomeThing..."); stopWatch.Stop(); times1 = stopWatch.ElapsedMilliseconds; if (times1 > DelayTime) { Console.WriteLine("Delay Time Over!"); stopWatch.Restart(); Thread.Sleep(1000); stopWatch.Stop(); var _time = stopWatch.ElapsedMilliseconds; Console.WriteLine(_time); break; } } } }