2018年3月27日 星期二

C# Sample

1.Use Environment.TickCount property. 
[code]
function Delay(int ms)
{
int time = Environment.TickCount;
do while(true)
if(Environment.TickCount - time >= ms) return;
}
[/code]

2.it calculats the Time Laspe From the System Clock
[code]
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 ;
}
[/code]

沒有留言:

張貼留言