C#限制并发线程数例程2011-07-07 博客园 Kevin Cheng按自己的想法实现的C#版本的限制并发线程数的例程,给有需要的读者using System; using System.Collections.Generic; using System.Text; using System.Threading;
namespace WZDM.Test { /// <summary> /// 限制并发线程数例程 /// </summary> public class TestThread { int _currentThreads = 0; int _maxThreads = 10;
public void Test() { while (true) { //_maxThreads = new Random().Next(1, 10); for (int i=0; i<100; i++) { // 在此进行数量限制 if (_currentThreads >= _maxThreads) break;