线程的定义我想大家都有所了解,这里我就不再复述了。我这里主要介绍.NET Framework中的线程(Thread、ThreadPool)。
.NET Framework中的线程分为两类:1.前台线程;2.后台线程。
1.前台线程
class Program { static void Main(string[] args) { Console.WriteLine("=====Thread====="); TestThread(); Console.WriteLine("主线程执行完毕"); } public static void TestThread() { Thread thread = new Thread(PrintNum); thread.Start(); } public static void PrintNum() { Thread.Sleep(3000); for (int i = 0; i < 10; i++) Console.WriteLine(i); } }