zoukankan      html  css  js  c++  java
  • ThreadPool 简单的用法

    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);
                }
            }
        }
    }

  • 相关阅读:
    假期第五天
    假期第四天
    假期第三天
    假期第二天
    假期第一天
    《如何高效学习》读书笔记六
    十天冲刺-第八天
    十天冲刺第七天
    十天冲刺-第六天
    十天冲刺-第五天
  • 原文地址:https://www.cnblogs.com/w2011/p/2700318.html
Copyright © 2011-2022 走看看