using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { //Stopwatch用于记录代码运行时间 Stopwatch watch1 = new Stopwatch(); watch1.Start(); for (int i = 1; i <= 10; i++) { Console.WriteLine(i ); Thread.Sleep(1000); } watch1.Stop(); Console.WriteLine(watch1.Elapsed); Stopwatch watch2 = new Stopwatch(); watch2.Start(); //会调用线程池中的线程 Parallel.For(1, 11, i => { Console.WriteLine(i + ",线程ID:" + Thread.CurrentThread.ManagedThreadId); //Thread.Sleep(1000); }); watch2.Stop(); Console.WriteLine(watch2.Elapsed); } } }