#2881382 - An item with the same key has already been added, now its not added twice.

git-svn-id: svn://svn.code.sf.net/p/processhacker/code@2277 21ef857c-d57f-4fe0-8362-d861dc6d29cd
This commit is contained in:
dmex04
2009-10-18 20:51:14 +00:00
parent 00c627fe14
commit 0a2c4e9921
@@ -49,49 +49,52 @@ namespace ProcessHacker
public void Add(ProcessItem item)
{
ProcessNode itemNode = new ProcessNode(item);
// Add the process to the list of all processes.
_processes.Add(item.Pid, itemNode);
// Find the process' parent and add the process to it if we found it.
if (item.HasParent && _processes.ContainsKey(item.ParentPid))
if (!_processes.ContainsKey(item.Pid))
{
ProcessNode parent = _processes[item.ParentPid];
// Add the process to the list of all processes.
_processes.Add(item.Pid, itemNode);
parent.Children.Add(itemNode);
itemNode.Parent = parent;
}
else
{
// The process doesn't have a parent, so add it to the root nodes.
_roots.Add(itemNode);
}
itemNode.RefreshTreePath();
// Find this process' children and fix them up.
// We need to create a copy of the array because we may need
// to modify the roots list.
ProcessNode[] roots = _roots.ToArray();
foreach (ProcessNode node in roots)
{
// Notice that we don't replace a node's parent if it
// already has one. This is to break potential cyclic
// references.
if (node.Parent == null && node.ProcessItem.HasParent && node.PPid == item.Pid)
// Find the process' parent and add the process to it if we found it.
if (item.HasParent && _processes.ContainsKey(item.ParentPid))
{
// Remove the node from the root list and add it to our
// process' child list.
_roots.Remove(node);
itemNode.Children.Add(node);
node.Parent = itemNode;
node.RefreshTreePathRecursive();
}
}
ProcessNode parent = _processes[item.ParentPid];
this.StructureChanged(this, new TreePathEventArgs(new TreePath()));
parent.Children.Add(itemNode);
itemNode.Parent = parent;
}
else
{
// The process doesn't have a parent, so add it to the root nodes.
_roots.Add(itemNode);
}
itemNode.RefreshTreePath();
// Find this process' children and fix them up.
// We need to create a copy of the array because we may need
// to modify the roots list.
ProcessNode[] roots = _roots.ToArray();
foreach (ProcessNode node in roots)
{
// Notice that we don't replace a node's parent if it
// already has one. This is to break potential cyclic
// references.
if (node.Parent == null && node.ProcessItem.HasParent && node.PPid == item.Pid)
{
// Remove the node from the root list and add it to our
// process' child list.
_roots.Remove(node);
itemNode.Children.Add(node);
node.Parent = itemNode;
node.RefreshTreePathRecursive();
}
}
this.StructureChanged(this, new TreePathEventArgs(new TreePath()));
}
}
public void Modify(ProcessItem oldItem, ProcessItem newItem)