Make checking for process children less aggressive

This commit is contained in:
baldurk
2016-11-03 16:16:56 +01:00
parent efb47c6712
commit 503484c9c8
2 changed files with 36 additions and 24 deletions
+1
View File
@@ -467,6 +467,7 @@
// childUpdateTimer
//
this.childUpdateTimer.Enabled = true;
this.childUpdateTimer.Interval = 1000;
this.childUpdateTimer.Tick += new System.EventHandler(this.childUpdateTimer_Tick);
//
// LiveCapture
+35 -24
View File
@@ -910,35 +910,46 @@ namespace renderdocui.Windows
private void childUpdateTimer_Tick(object sender, EventArgs e)
{
// remove any stale processes
for (int i = 0; i < m_Children.Count; i++)
if (m_Children.Count > 0)
{
try
Process[] processes = Process.GetProcesses();
// remove any stale processes
for (int i = 0; i < m_Children.Count; i++)
{
// if this throws an exception the process no longer exists so we'll remove it
Process.GetProcessById(m_Children[i].PID);
bool found = false;
foreach (var p in processes)
{
if (p.Id == m_Children[i].PID)
{
found = true;
break;
}
}
if (!found)
{
if (m_Children[i].added)
childProcesses.Items.RemoveByKey(m_Children[i].PID.ToString());
// process expired/doesn't exist anymore
m_Children.RemoveAt(i);
// don't increment i, check the next element at i (if we weren't at the end
i--;
}
}
catch (Exception)
for (int i = 0; i < m_Children.Count; i++)
{
if (m_Children[i].added)
childProcesses.Items.RemoveByKey(m_Children[i].PID.ToString());
if (!m_Children[i].added)
{
string text = String.Format("{0} [PID {1}]", m_Children[i].name, m_Children[i].PID);
// process expired/doesn't exist anymore
m_Children.RemoveAt(i);
// don't increment i, check the next element at i (if we weren't at the end
i--;
}
}
for (int i = 0; i < m_Children.Count; i++)
{
if (!m_Children[i].added)
{
string text = String.Format("{0} [PID {1}]", m_Children[i].name, m_Children[i].PID);
m_Children[i].added = true;
childProcesses.Items.Add(m_Children[i].PID.ToString(), text, 0).Tag = m_Children[i].ident;
m_Children[i].added = true;
childProcesses.Items.Add(m_Children[i].PID.ToString(), text, 0).Tag = m_Children[i].ident;
}
}
}