C# Thread.Sleep替代方法

        public double sleep;//线程休眠时间

        /// 
        /// 线程休眠
        /// 
        /// 休眠时间,以毫秒为单位
        private void WaitDelayTime(double sleep)
        {
            Stopwatch sw = Stopwatch.StartNew();
            sw.Restart();
            while (true)
            {
                try
                {
                    Thread.Sleep(2);
                    bool flag = (double)sw.ElapsedMilliseconds >= sleep;
                    if (flag)
                    {
                        goto block;
                    }
                }
                catch (Exception ex)
                {

                }
            }
        block:
            return;
        }

你可能感兴趣的:(c#,开发语言)