.NET/C#

C# Delay 함수

★조군™ 2013. 8. 27. 14:12

public static DateTime Delay(int ms)
{
      DateTime ThisMoment = DateTime.Now;
      TimeSpan duration = new TimeSpan(0, 0, 0, 0, ms);
      DateTime AfterWards = ThisMoment.Add(duration);

      while (AfterWards >= ThisMoment)
      {
          System.Windows.Forms.Application.DoEvents();
          ThisMoment = DateTime.Now;
      }

      return DateTime.Now;
}

 

단위는 밀리초 1000 = 1초