private IThread NewThread(bool isMin = false) { IThread _thread = new WorkThread(_info.Timeout, isMin); _thread.ItemFinished += thread_FinishItem; _thread.Exited += thread_Exited; _thread.Start(); _threadCount++; _maxThreadCount = Math.Max(_maxThreadCount, _threadCount); return(_thread); }
/// <summary> /// Used to add work to the queue. /// </summary> /// <param name="WorkObject">The work object.</param> /// <param name="Delegate">The delegate.</param> public void QueueWork(object WorkObject, WorkDelegate Delegate) { WorkItem wi = new WorkItem(); wi.WorkObject = WorkObject; wi.Delegate = Delegate; lock (WorkQueue) { WorkQueue.Enqueue(wi); } //Now see if there are any threads that are idle bool FoundIdleThread = false; foreach (WorkThread wt in ThreadList) { if (!wt.Busy) { wt.WakeUp(); FoundIdleThread = true; break; } } if (!FoundIdleThread) { //See if we can create a new thread to handle the additional workload if (ThreadList.Count < m_MaxThreads) { WorkThread wt = new WorkThread(ref WorkQueue); lock (ThreadList) { ThreadList.Add(wt); } } } }