C#控制台应用程序 多线程获取系统时间
设计一个能显示时间的C#控制台应用程序。要求使用多线程技术,在子线程中每隔一秒钟获取系统当前的时间,并显示在控制台中,总共显示10次。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace sx9_1 { class Program { static void Main(string[] args) { Thread timeThread = new Thread(new ThreadStart(GetTime)); timeThread.Start(); }//copy from iotword.com private static void GetTime() { int i = 1; Console.Clear(); do { Console.WriteLine(System.DateTime.Now.ToString()); Thread.Sleep(1000);//copy from iotword.com i++; } while (i <= 10); Console.WriteLine(System.DateTime.Now.ToString()); } } }