亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#延時(shí)函數(shù)的使用說明

 更新時(shí)間:2022年04月20日 09:43:31   作者:海歌也瘋狂  
這篇文章主要介紹了C#延時(shí)函數(shù)的使用說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

C#延時(shí)函數(shù)使用

在線程中如果需要延時(shí),盡量不要使用Sleep()函數(shù),這樣會(huì)導(dǎo)致時(shí)間片切到別的線程中。

使用如下函數(shù): 

? ? //Delay function
? ? public static void Delay(int milliSecond)
? ? {
? ? ? ? int start = Environment.TickCount;
? ? ? ? while (Math.Abs(Environment.TickCount - start) < milliSecond)
? ? ? ? {
? ? ? ? ? ? Application.DoEvents();
? ? ? ? ?}
? ? }

或者:

? ? ? ? //Delay us ? Create a waitable timer
? ? ? ? [DllImport("kernel32.dll")]
? ? ? ? public static extern int CreateWaitableTimer(int lpTimerAttributes,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bool bManualReset, int lpTimerName);
?
? ? ? ? public static void UsDelay(int us)
? ? ? ? {
? ? ? ? ? ? long duetime = -10 * us;
? ? ? ? ? ? int hWaitTimer = CreateWaitableTimer(NULL, true, NULL);
? ? ? ? ? ? SetWaitableTimer(hWaitTimer, ref duetime, 0, NULL, NULL, false);
? ? ? ? ? ? while (MsgWaitForMultipleObjects(1, ref hWaitTimer, false, Timeout.Infinite,?
? ? ? ? ? ? ? ? ? ? QS_TIMER)) ;
? ? ? ? ? ? CloseHandle(hWaitTimer);
? ? ? ? }

C#3個(gè)延時(shí)函數(shù) 

public static void Delays(int DelayTime = 100)
        {
            int time = Environment.TickCount;
            while (true)
            {
                if (Environment.TickCount - time >= DelayTime)
                {
                    break;
                }
                Application.DoEvents();
                Thread.Sleep(10);
            }
        }
 
        public static void Delay1(int milliSecond)
        {
            int start = Environment.TickCount;
            while (Math.Abs(Environment.TickCount - start) < milliSecond)
            {
                Application.DoEvents();
            }
        }
 
        //延時(shí)程序 秒
        public static bool Delay2(int delayTime)
        {
            DateTime now = DateTime.Now;
            int s;
            do
            {
                TimeSpan spand = DateTime.Now - now;
                s = spand.Seconds;
                Application.DoEvents();
            }
            while (s < delayTime);
            return true;
        }

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論