Ejemplo n.º 1
0
        /// <summary>计时,并用控制台输出行</summary>
        /// <param name="title">标题</param>
        /// <param name="times">次数</param>
        /// <param name="action">需要计时的委托</param>
        /// <param name="needTimeOne">是否需要预热</param>
        public static void TimeLine(String title, Int32 times, Action <Int32> action, Boolean needTimeOne = true)
        {
            var n = Encoding.Default.GetByteCount(title);

            Console.Write("{0}{1}:", n >= 16 ? "" : new String(' ', 16 - n), title);

            var timer = new CodeTimer();

            timer.Times        = times;
            timer.Action       = action;
            timer.ShowProgress = true;
#if !Android
            var currentForeColor = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.Yellow;
            Int32 left = Console.CursorLeft;
#endif
            if (needTimeOne)
            {
                timer.TimeOne();
            }
            timer.Time();

            // 等一会,让进度那边先输出
            Thread.Sleep(10);
#if !Android
            Console.CursorLeft = left;
#endif
            Console.WriteLine(timer.ToString());
#if !Android
            Console.ForegroundColor = currentForeColor;
#endif
        }
Ejemplo n.º 2
0
        /// <summary>计时,并用控制台输出行</summary>
        /// <param name="title">标题</param>
        /// <param name="times">次数</param>
        /// <param name="action">需要计时的委托</param>
        /// <param name="needTimeOne">是否需要预热</param>
        public static CodeTimer TimeLine(String title, Int32 times, Action <Int32> action, Boolean needTimeOne = true)
        {
            var n = Encoding.UTF8.GetByteCount(title);

            Console.Write("{0}{1}:", n >= 16 ? "" : new String(' ', 16 - n), title);

            var timer = new CodeTimer
            {
                Times        = times,
                Action       = action,
                ShowProgress = true
            };
            var currentForeColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Yellow;
            var left = Console.CursorLeft;

            if (needTimeOne)
            {
                timer.TimeOne();
            }
            timer.Time();

            // 等一会,让进度那边先输出
            Thread.Sleep(10);
            Console.CursorLeft = left;
            Console.WriteLine(timer.ToString());
            Console.ForegroundColor = currentForeColor;

            return(timer);
        }
Ejemplo n.º 3
0
        /// <summary>计时</summary>
        /// <param name="times">次数</param>
        /// <param name="action">需要计时的委托</param>
        /// <param name="needTimeOne">是否需要预热</param>
        /// <returns></returns>
        public static CodeTimer Time(Int32 times, Action <Int32> action, Boolean needTimeOne = true)
        {
            var timer = new CodeTimer();

            timer.Times  = times;
            timer.Action = action;

            if (needTimeOne)
            {
                timer.TimeOne();
            }
            timer.Time();

            return(timer);
        }