C# 控制台计时器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
 
namespace ConsoleApplication3
{
    
    
   class Program
   {
    
    
       static void Main(string[] args)
       {
    
    
           Timer t = new Timer();
           t.Elapsed += new ElapsedEventHandler(OnTimedEvent);
           t.Interval = 1000;
           t.Enabled = true;
           Console.Read();
       }
 
       private static void OnTimedEvent(object source, ElapsedEventArgs e)
       {
    
    
           Console.Clear();
           Console.WriteLine(DateTime.Now);
       }
   }
}

原文:https://blog.csdn.net/yiwangxiblog/article/details/74009170

猜你喜欢

转载自blog.csdn.net/weixin_45023328/article/details/120888792