国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#通過Semaphore類控制線程隊列的方法

2020-01-24 01:29:49
字體:
來源:轉載
供稿:網友

本文實例講述了C#通過Semaphore類控制線程隊列的方法。分享給大家供大家參考。具體實現方法如下:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using System.Diagnostics;using System.Threading;using System.ComponentModel;using System.Collections;using System.Net;using System.Runtime.Serialization;using System.Xml;using System.Globalization;using System.Text.RegularExpressions;using System.Data;using System.Data.SqlClient;namespace ConsoleApp{ /// <summary> /// 線程控制隊列 /// Semaphore類 /// </summary> class Program {  static Semaphore semaphore;  static void Main(string[] args)  {   semaphore = new Semaphore(0, 2);   Thread thread;   for (int i = 0; i <= 5; i++)   {    thread = new Thread(new ParameterizedThreadStart(Run));    thread.Start("thread_"+i.ToString());   }   semaphore.Release(2);   Console.ReadLine();  }  static void Run(object obj)  {   semaphore.WaitOne();   Console.WriteLine("thread " + obj.ToString() + " into the method");   System.Threading.Thread.Sleep(5000);      Console.WriteLine("_thread " + obj.ToString() + " leave the method");   semaphore.Release();  } }}

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 韩城市| 乾安县| 高清| 泗洪县| 神木县| 汶川县| 丹阳市| 珲春市| 大洼县| 迁西县| 齐河县| 吴江市| 屏山县| 滦南县| 河间市| 甘泉县| 楚雄市| 玉田县| 双牌县| 岢岚县| 南雄市| 贵南县| 开封市| 都昌县| 陵川县| 广西| 桐城市| 嘉禾县| 崇义县| 巴彦淖尔市| 浦江县| 芒康县| 康乐县| 兴安盟| 玉环县| 城口县| 安塞县| 荆州市| 天柱县| 陇南市| 合川市|