private static TimerExecuter CreateThread() { TimerExecuter timerExecuter = new TimerExecuter(ThreadCompleted); _timerThreads.Add(timerExecuter); timerExecuter.Start(); return(timerExecuter); }
private static void ThreadCompleted(TimerExecuter executer) { _ = _DEBUG; // bool flag = 1 == 0; lock (_queueCompleteThreads) { _queueCompleteThreads.Enqueue(executer); } }
private static void ThreadReset(TimerExecuter executer) { lock (_queueCompleteThreads) { if (!_queueCompleteThreads.Contains(executer)) { _queueCompleteThreads.Enqueue(executer); } } }
private static void Thread2() { int num = 200; while (true) { bool flag = true; long tickCount = TickCount; while (_queueTimers.Count > 0) { TimerInfo timerInfo = null; lock (_queueTimers) { if (_queueTimers.Count > 0) { TimerInfo timerInfo2 = _queueTimers.Dequeue(); if (timerInfo2 != null && _dicTimers.ContainsKey(timerInfo2.Key)) { timerInfo = timerInfo2; } } } if (timerInfo == null) { continue; } TimerExecuter timerExecuter = null; while (true) { flag = true; timerExecuter = GetIdleThread(); if (timerExecuter != null) { break; } Thread.Sleep(1); } if (timerInfo == null) { throw new Exception("item null"); } timerExecuter.Run(timerInfo); } long tickCount2 = TickCount; if (tickCount2 - tickCount < 5) { Thread.Sleep(5); } } }
private static TimerExecuter GetIdleThread() { if (_queueIdleThreads.Count > 0) { return(_queueIdleThreads.Dequeue()); } while (_queueCompleteThreads.Count > 0) { TimerExecuter timerExecuter = _queueCompleteThreads.Peek(); timerExecuter = _queueCompleteThreads.Dequeue(); _queueIdleThreads.Enqueue(timerExecuter); } if (_queueIdleThreads.Count > 0) { return(_queueIdleThreads.Dequeue()); } if (_timerThreads.Count <= _maxThread) { return(CreateThread()); } return(null); }