欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當(dāng)前位置:主頁 > 軟件編程 > C#教程 >

C#多線程ThreadPool線程池詳解

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C#教程|點(diǎn)擊: 次

簡單說明一下:

線程池可以看做容納線程的容器;一個(gè)應(yīng)用程序最多只能有一個(gè)線程池;ThreadPool靜態(tài)類通過QueueUserWorkItem()方法將工作函數(shù)排入線程池; 每排入一個(gè)工作函數(shù),就相當(dāng)于請求創(chuàng)建一個(gè)線程;

線程池的作用:

1、線程池是為突然大量爆發(fā)的線程設(shè)計(jì)的,通過有限的幾個(gè)固定線程為大量的操作服務(wù),減少了創(chuàng)建和銷毀線程所需的時(shí)間,從而提高效率。
2、如果一個(gè)線程的時(shí)間非常長,就沒必要用線程池了(不是不能作長時(shí)間操作,而是不宜。),況且我們還不能控制線程池中線程的開始、掛起、和中止。

一些使用例子:

實(shí)例一:

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

namespace ThreadPoolDemo
{
 class Program
 {
  static void Main(string[] args)
  {
   System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(TestThreadPool),new string[] {"drsw","sfs","sdfs"});
   Console.ReadKey();
  }

  public static void TestThreadPool(object state)
  {
   string[] arry = state as string[]; //傳過來的參數(shù)值
   int workerThreads = 0;
   int completionPortThreads = 0;
   System.Threading.ThreadPool.GetMaxThreads(out workerThreads, out completionPortThreads);

   Console.Write(DateTime.Now.ToString() + "--" + arry[0] + "----workerThreads=" + workerThreads + "----completionPortThreads=" + completionPortThreads);
  }
 }
}

上述代碼運(yùn)行結(jié)果:

使用例子二:

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

namespace ThreadPoolDemo
{
 class Program
 {
  static void Main(string[] args)
  {
   System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(TestThreadPool));
   Console.ReadKey();
  }

  public static void TestThreadPool(object state)
  {
   int workerThreads = 0;
   int completionPortThreads = 0;
   System.Threading.ThreadPool.GetMaxThreads(out workerThreads, out completionPortThreads);

   Console.Write(DateTime.Now.ToString() + "----workerThreads=" + workerThreads + "----completionPortThreads=" + completionPortThreads);
  }
 }
}

上述代碼運(yùn)行結(jié)果:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:C#實(shí)現(xiàn)微信結(jié)合百度api獲取當(dāng)前用戶地理位置的方法

欄    目:C#教程

下一篇:C#微信接口之推送模板消息功能示例

本文標(biāo)題:C#多線程ThreadPool線程池詳解

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/5596.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有