c#延时程序

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bayinglong/article/details/74253927

有效避免sleep带来的线程休眠问题(如界面假死)

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

TickCount为毫秒级延时,milliSecond为设置的延时时间,用Math. Abs的原因是Environment.TickCount有部分时间为负数。

猜你喜欢

转载自blog.csdn.net/bayinglong/article/details/74253927