private void OnWorkComplete(CThread thread, ICWorkItem task) { Interlocked.Increment(ref _finishedCount); ICWorkItem newTask; bool hasWorkDo = false; try { if (_ThreadWorkCompleteCallback != null) { _ThreadWorkCompleteCallback(task); } } catch (Exception ex) { CHystrix.Utils.CommonUtils.Log.Log(LogLevelEnum.Error, ex.Message, ex); } if (_nowRunningCount + _idleThreads.Count > _MaxConcurrentCount) { thread.Shutdown(); } if (!thread.IsShutdown) { while (_waitingTasks.TryDequeue(out newTask)) { if (newTask.CanDo(this.WorkItemTimeoutMiliseconds)) { thread.DoWork(newTask); hasWorkDo = true; break; } else if (newTask.MarkTimeout()) { Interlocked.Increment(ref _timeoutCount); } } } if (!hasWorkDo) { CThread tmp; if (_threads.TryRemove(thread.ThreadID, out tmp)) { Interlocked.Decrement(ref _nowRunningCount); _idleThreads.Enqueue(thread); } } }
private void OnWorkComplete(CThread thread, ICWorkItem task) { CThread thread2; Interlocked.Increment(ref this._finishedCount); bool flag = false; try { if (this._ThreadWorkCompleteCallback != null) { this._ThreadWorkCompleteCallback(task); } } catch (Exception exception) { CommonUtils.Log.Log(LogLevelEnum.Error, exception.Message, exception); } if ((this._nowRunningCount + this._idleThreads.Count) > this._MaxConcurrentCount) { thread.Shutdown(); } if (!thread.IsShutdown) { ICWorkItem item; while (this._waitingTasks.TryDequeue(out item)) { if (item.CanDo(this.WorkItemTimeoutMiliseconds)) { thread.DoWork(item); flag = true; break; } if (item.MarkTimeout()) { Interlocked.Increment(ref this._timeoutCount); } } } if (!flag && this._threads.TryRemove(thread.ThreadID, out thread2)) { Interlocked.Decrement(ref this._nowRunningCount); this._idleThreads.Enqueue(thread); } }