using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ThreadPoolDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            int nWorkerThreads;
            int nCompletionPorteads;
            ThreadPool.GetMaxThreads(out nWorkerThreads, out nCompletionPorteads);
            Console.WriteLine("Max worker threads:{0} Completion Threads:{1}", nWorkerThreads, nCompletionPorteads);

           for(int i=0;i<5;i++)
           {
               ThreadPool.QueueUserWorkItem(JobForAthread);
           }
           Thread.Sleep(3000);
        }

        static void JobForAthread(object state)
        {
            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine("Loop {0},Running inside pooled thread{1}",i, Thread.CurrentThread.ManagedThreadId);
                Thread.Sleep(50);
            }
        }
    }
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-04-21
  • 2021-10-16
  • 2022-01-02
  • 2021-12-05
  • 2021-06-18
  • 2021-07-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-14
  • 2022-12-23
  • 2021-12-24
相关资源
相似解决方案