zoukankan      html  css  js  c++  java
  • C#控制台源程序分享

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;                        //需要用到线程
    namespace timer016
    {
        class Program
        {
            static void Main(string[] args)
            {
                StopWatch sw = new StopWatch();
                sw.Start();
            }
        }

        class StopWatch
        {
            private int Interval = 1000;               //时间间隔,单位毫秒
            private int Time = 0;                       //所显示的时间

            public void Start()
            {
                Thread timer = new Thread(new ThreadStart(Timer)); //新建一个线程,该线程调用Timer()
                timer.Start();                              //启动线程
                Console.CursorVisible = false;   //隐藏光标
                Console.ReadKey(true);           //等待按任意键退出
                timer.Abort();                              //终止线程,用于停止秒表
            }

            private void Timer()
            {
                while (true)
                {
                    Display();                               //显示秒表计数
                    Thread.Sleep(Interval);          //等待1秒后再执行Timer()刷新计数
                    Time++;                                 //秒数加1
                }
            }

            private void Display()
            {
                Console.SetCursorPosition(0, 0);
                Console.Write("Time:" + Time.ToString());
            }
        }
    }

  • 相关阅读:
    Nginx+Lua学习笔记-环境搭建
    Scala学习笔记-Servlet环境搭建
    Scala学习笔记-环境搭建以及简单语法
    Python v3.4 not found的解决方法
    【闲聊】最近一段时间的总结
    javassist初接触
    java调用cmd
    Flexpaper初接触
    Derby初接触
    LVS Keepalived 集群
  • 原文地址:https://www.cnblogs.com/yuerdongni/p/2197064.html
Copyright © 2011-2022 走看看