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;
            }

        }
    }
}

 

posted @ 2018-05-02 14:14  Hello_2018  阅读(394)  评论(0编辑  收藏  举报