.net 线程池的简单应用
static void Main(string[] args)
{
ThreadPool.SetMinThreads(5, 5);
ThreadPool.SetMaxThreads(10, 10); for (int i = 1000; i >1; i--) { //string taskInfo = i.ToString() + "运行10秒"; // 插入一个新的请求到线程池 bool result = ThreadPool.QueueUserWorkItem(DoWork, i); } Console.ReadKey(); } private static void DoWork(object state) { Console.WriteLine("工作者线程的任务是:{0}", state); Thread.Sleep(4000); }