2011/09/22

[C#] Delay

// #1 Using Thread Sleep method
Thread.Sleep(5000);

// #2 Using TickCount
public void Delay(int ms)
{
int time = Environment.TickCount;

do
{
if(Environment.TickCount - time >= ms) return;
} while(true)
}

// #3 Using DateTime
public static DateTime PauseForMilliSeconds( int MilliSecondsToPauseFor )
{
System.DateTime ThisMoment = System.DateTime.Now;
System.TimeSpan duration = new System.TimeSpan( 0, 0, 0, 0, MilliSecondsToPauseFor );
System.DateTime AfterWards = ThisMoment.Add( duration );

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

return System.DateTime.Now;
}
<

Original Post : http://neodreamer-dev.tistory.com/578

No comments :

Post a Comment