public void Update() { //handle any incoming commands... lock (s_lockObject) { foreach (int pid in m_pidsToValidate) { // if (m_processManager.FindProcessById(pid)) { MonitoredProcess proc; if (m_processes.TryGetValue(pid, out proc)) { m_processes[pid] = new MonitoredProcess(pid); } else { m_processes.Add(pid, new MonitoredProcess(pid)); } } } m_pidsToValidate.Clear(); //check for missing pids foreach (var pair in m_processes) { if (!m_processManager.FindProcessById(pair.Key)) { m_pidsToValidate.Add(pair.Key); } } foreach (int pid in m_pidsToValidate) { m_processes.Remove(pid); } m_pidsToValidate.Clear(); //check for pid timeouts foreach (var pair in m_processes) { int secondsSinceLastHeartbeat = (DateTime.Now - pair.Value.m_startTime).Seconds; if (secondsSinceLastHeartbeat >= 30) { Console.WriteLine("Restart " + pair.Key); m_processManager.RestartProcessById(pair.Key); } } } }