/// <summary> /// 线程执行报错 /// </summary> /// <param name="item"></param> private void ErrorThread(ItemThread item) { KeyValuePair <string, string> pair = new KeyValuePair <string, string>(item.Id, item.ErrorCode); lock (errorDic) { ErrorMessageHandle handler; //errorDic.Add(pair); if (errorDic.TryGetValue(item.Id, out handler)) { if (handler != null) { handler(item.ErrorCode); } errorDic.Remove(item.Id); } errorList.Add(pair); } lock (curAliveThreadCountLock) curAliveThreadCount--; lock (destoryObjLock) if (isDestory) { item.Stop(); return; } ThreadQueueHandle(); }
/// <summary> /// 销毁线程池 /// </summary> public void Destory() { lock (destoryObjLock) isDestory = true; lock (idleQueue) { for (int i = idleQueue.Count - 1; i >= 0; i--) { ItemThread item = idleQueue.Dequeue(); item.Stop(); } } lock (weightQueue) weightQueue.Clear(); }
/// <summary> /// 线程执行完毕,回归等待队列 /// </summary> /// <param name="item"></param> private void EndThread(ItemThread item) { lock (aliveList) aliveList.Remove(item); lock (curAliveThreadCountLock) curAliveThreadCount--; lock (destoryObjLock) if (isDestory) { item.Stop(); return; } lock (idleQueue) idleQueue.Enqueue(item); ThreadQueueHandle(); }