Пример #1
0
        // Refresh the tree
        //
        private void TreeRefresh(bool FullRefresh)
        {
            int     KillSwitch = 0;
            PidList Updates    = new PidList();

            Updates.GetSystemPids(true);             // Load system processes
            Updates.Remove("idle", PidFields.Name);  // Remove the Idles
            Running.Remove("idle", PidFields.Name);

            if (FullRefresh)                          // Clear the running processes
            {
                Running.Clear();                      // so the Diff will think
                PidTree.Nodes.Clear();                // everything's new

                TreeNode Root = new TreeNode("Idle"); // Add Idle process to the tree
                Root.Name = "0";
                PidTree.Nodes.Add(Root);
            }

            PidDiff Result = Running.Diff(Updates);     // Execute a Diff

            PruneBranches(Result.Removed);              // Kill Removed

            // Add nodes loop
            //
            while (Result.Added.Count != 0 && KillSwitch < 9)
            {
                Result.Added = AddBranches(Result.Added);
                KillSwitch++;
            }

            if (FullRefresh)                         // Collapse the Tree
            {
                PidTree.CollapseAll();

                TreeNode[] t = PidTree.Nodes.Find("0", true);  // Expand Idle
                t[0].Expand();
                PidTree.LastNode  = t[0];
                txtProcessID.Text = $"Idle (0)";

                // Expand Explorer
                //
                Pid tmpPid = Running.Find("explorer", PidFields.Name);  // Search for explorer
                if (tmpPid != null)
                {
                    t = PidTree.Nodes.Find(tmpPid.Id.ToString(), true); // Highlight explorer
                    t[0].Expand();

                    txtProcessID.Text    = $"{tmpPid.Name} ({tmpPid.Id})";
                    PidTree.SelectedNode = t[0];
                    PidTree.LastNode     = t[0];
                    t[0].EnsureVisible();
                }
            }

            txtProcessCount.Text = $"Processes: {Running.Count}";
        }
Пример #2
0
        // UI: Selected something from the context menu
        //
        private new void ContextMenu(object sender, EventArgs e)
        {
            string  cmd = ((ToolStripMenuItem)sender).Text;
            PidList kill;

            UpdatePids.Enabled = false;  // Stop Auto refresh

            switch (cmd)
            {
            case "Kill Process":
                // Will re parent any orphans
                //
                kill = PidTree.GeneratePidList(Running);
                foreach (Pid p in kill)
                {
                    Running.Remove(p.Id, PidFields.Id);
                }

                // Kill it
                //
                int pid = Convert.ToInt32(PidTree.LastNode.Name);
                try {
                    Process.GetProcessById(pid).Kill();
                } catch { }

                PidTree.LastNode.Remove();
                break;

            case "Kill Process Tree":
                kill = PidTree.GeneratePidList(Running);

                foreach (Pid p in kill)
                {
                    try {
                        Running.Remove(p.Id, PidFields.Id);
                        Process.GetProcessById(p.Id).Kill();
                    } catch { }
                }

                PidTree.LastNode.Remove();
                break;
            }

            TreeRefresh(false);
            UpdatePids.Enabled = true;  // Start Auto refresh
        }