c#的线程池,第一次用

来源:互联网 发布:阿里云是阿里巴巴的吗 编辑:程序博客网 时间:2024/06/08 05:25
static void ThreadFileDeal(object i)
        {


            string strGet = (string)i;
            for (int a = 0; a < 5; a++)
            {
                Console.WriteLine(Thread.CurrentThread.ManagedThreadId.ToString() + strGet);
                Thread.Sleep(1000);
            }
                
        }


        static void WaitCallBackMethod(object param)
        {
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(String.Format("Thread {0} is running", param));
                Thread.Sleep(1000);
            }
        }




        static void Main(string[] args)
        {
            int ncount = 0;
           while(ncount<100)
            {
                ncount++;
                ThreadPool.SetMaxThreads(20, 20);


                ThreadPool.QueueUserWorkItem(WaitCallBackMethod, ncount);//第一个启动的方法
                ThreadPool.QueueUserWorkItem(ThreadFileDeal,"temp");//第二个启动的方法
            }
             Console.Read();


        }
0 0
原创粉丝点击