• 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());
            }
        }
    }

  • 相关阅读:
    nodejs初期,搭建一个登陆注册功能,(原生的)
    关于vue如何创建一个自定义组件(这是项目中经常得用的)
    关于vue 使用watch方法,详解。
    怎样用Nodejs搭建一个服务器
    关于Promise的理解及运用
    Ado.NET SQLHelper(2)
    Ado.NET SQLHelper
    MS SQLSERVER 自增ID列竟然会重复
    SQL中Left Join 与Right Join 与 Inner Join 与 Full Join的区别
    thread.start和threadstart.invoke的区别
  • 原文地址:https://www.cnblogs.com/yuerdongni/p/2197064.html
Copyright © 2020-2023  润新知