コード例 #1
0
        /// <summary>
        /// Pause the program for the specified number of milliseconds, displaying a period at a set interval while paused
        /// </summary>
        /// <param name="millisecondsToPause">Milliseconds to pause; default 5 seconds</param>
        /// <param name="millisecondsBetweenDots">Seconds between each period; default 1 second</param>
        public static void PauseAtConsole(int millisecondsToPause = 5000, int millisecondsBetweenDots = 1000)
        {
            int totalIterations;

            Console.WriteLine();
            Console.Write("Continuing in " + (millisecondsToPause / 1000.0).ToString("0") + " seconds ");

            try
            {
                if (millisecondsBetweenDots == 0)
                {
                    millisecondsBetweenDots = millisecondsToPause;
                }

                totalIterations = (int)Math.Round(millisecondsToPause / (double)millisecondsBetweenDots, 0);
            }
            catch
            {
                // Ignore errors here
                totalIterations = 1;
            }

            var iteration = 0;

            do
            {
                Console.Write('.');

                ProgRunner.SleepMilliseconds(millisecondsBetweenDots);

                iteration += 1;
            } while (iteration < totalIterations);

            Console.WriteLine();
        }
コード例 #2
0
        /// <summary>
        /// Sleep for the specified number of seconds
        /// </summary>
        /// <param name="waitTimeSeconds"></param>
        /// <remarks>Sleeps for 10 second chunks until waitTimeSeconds has elapsed</remarks>
        public static void SleepSeconds(double waitTimeSeconds)
        {
            var endTime = DateTime.UtcNow.AddSeconds(waitTimeSeconds);

            while (endTime.Subtract(DateTime.UtcNow).TotalMilliseconds > 10)
            {
                var remainingSeconds = endTime.Subtract(DateTime.UtcNow).TotalSeconds;
                if (remainingSeconds > 10)
                {
                    ProgRunner.SleepMilliseconds(10000);
                }
                else
                {
                    var sleepTimeMsec = (int)Math.Ceiling(remainingSeconds * 1000);
                    ProgRunner.SleepMilliseconds(sleepTimeMsec);
                }
            }
        }