public CustomThreadPool(int numThreads, CustomRunDelegate customRun) { if (numThreads <= 0) { throw new ArgumentOutOfRangeException("numThreads"); } threads = new List <Thread>(numThreads); queue = new Queue <WaitQueueItem>(); workWaiting = new Semaphore(0, int.MaxValue); for (int i = 0; i < numThreads; i++) { ThreadStart ts; if (customRun != null) { ts = delegate { customRun(InternalRun); } } ; else { ts = InternalRun; } var t = new Thread(ts) { IsBackground = true }; t.Name = String.Format("p{0}.{1}", poolId, t.ManagedThreadId); threads.Add(t); t.Start(); } }
public CustomThreadPool(int numThreads, CustomRunDelegate customRun) { if (numThreads <= 0) throw new ArgumentOutOfRangeException("numThreads"); threads = new List<Thread>(numThreads); queue = new Queue<WaitQueueItem>(); workWaiting = new Semaphore(0, int.MaxValue); for (int i = 0; i < numThreads; i++) { ThreadStart ts; if (customRun != null) ts = delegate { customRun(InternalRun); }; else ts = InternalRun; var t = new Thread(ts) { IsBackground = true }; t.Name = String.Format("p{0}.{1}", poolId, t.ManagedThreadId); threads.Add(t); t.Start(); } }