/// <summary> /// Run the loop through the heartbeats. /// </summary> protected internal void Run() { Culture.SetCurrentCulture(); try { List <InternalHeartbeat> hbToRemove = null; while ((m_timesToIterate >= 0) && (!startedshutdown)) { lock (m_lock) { foreach (InternalHeartbeat intHB in m_heartbeats) { bool isRunning = false; if (!CallAndWait(intHB.millisecondTimeOut, intHB.heartBeat, out isRunning)) { MainConsole.Instance.Warn( "[ThreadTracker]: Could not run Heartbeat in specified limits!"); } else if (!isRunning) { if (hbToRemove == null) { hbToRemove = new List <InternalHeartbeat>(); } hbToRemove.Add(intHB); } } if (hbToRemove != null) { foreach (InternalHeartbeat intHB in hbToRemove) { m_heartbeats.Remove(intHB); } //Renull it for later hbToRemove = null; if (m_heartbeats.Count == 0) //None left, break { break; } } } //0 is infinite if (m_timesToIterate != 0) { //Subtract, then see if it is 0, and if it is, it is time to stop m_timesToIterate--; if (m_timesToIterate == 0) { break; } } if (m_timesToIterate == -1) //Kill signal { break; } if (m_sleepTime != 0) { Thread.Sleep(m_sleepTime); } } } catch { } Thread.CurrentThread.Abort(); }