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

  • 相关阅读:
    elementUI使用el-tabs时有个坑
    滚动条滚动到指定位置(锚点)的不同实现方式
    elementUI组件 el-checkbox 的值格式问题
    前端常见面试题(七)ajax
    this指向 以及 call、apply、bind的使用和区别
    vue 项目目录解释
    vue-lic
    vue 网络请求 axios
    vue 状态管理 vuex
    keep-alive+vue 路由 (vue-router)
  • 原文地址:https://www.cnblogs.com/yuerdongni/p/2197064.html
Copyright © 2011-2022 走看看