Esempio n. 1
0
        private void menuThread_Popup(object sender, EventArgs e)
        {
            if (listThreads.SelectedItems.Count == 0)
            {
                menuThread.DisableAll();

                return;
            }
            else if (listThreads.SelectedItems.Count == 1)
            {
                menuThread.EnableAll();

                terminateThreadMenuItem.Text = "&Terminate Thread";
                forceTerminateThreadMenuItem.Text = "Force Terminate Thread";
                suspendThreadMenuItem.Text = "&Suspend Thread";
                resumeThreadMenuItem.Text = "&Resume Thread";
                priorityThreadMenuItem.Text = "&Priority";

                timeCriticalThreadMenuItem.Checked = false;
                highestThreadMenuItem.Checked = false;
                aboveNormalThreadMenuItem.Checked = false;
                normalThreadMenuItem.Checked = false;
                belowNormalThreadMenuItem.Checked = false;
                lowestThreadMenuItem.Checked = false;
                idleThreadMenuItem.Checked = false;

                ioPriority0ThreadMenuItem.Checked = false;
                ioPriority1ThreadMenuItem.Checked = false;
                ioPriority2ThreadMenuItem.Checked = false;
                ioPriority3ThreadMenuItem.Checked = false;

                try
                {
                    using (var thandle = new ThreadHandle(
                        int.Parse(listThreads.SelectedItems[0].SubItems[0].Text), 
                        Program.MinThreadQueryRights))
                    {
                        try
                        {
                            switch (thandle.GetBasePriorityWin32())
                            {
                                case ThreadPriorityLevel.TimeCritical:
                                    timeCriticalThreadMenuItem.Checked = true;
                                    break;
                                case ThreadPriorityLevel.Highest:
                                    highestThreadMenuItem.Checked = true;
                                    break;
                                case ThreadPriorityLevel.AboveNormal:
                                    aboveNormalThreadMenuItem.Checked = true;
                                    break;
                                case ThreadPriorityLevel.Normal:
                                    normalThreadMenuItem.Checked = true;
                                    break;
                                case ThreadPriorityLevel.BelowNormal:
                                    belowNormalThreadMenuItem.Checked = true;
                                    break;
                                case ThreadPriorityLevel.Lowest:
                                    lowestThreadMenuItem.Checked = true;
                                    break;
                                case ThreadPriorityLevel.Idle:
                                    idleThreadMenuItem.Checked = true;
                                    break;
                            }
                        }
                        catch
                        {
                            priorityThreadMenuItem.Enabled = false;
                        }

                        try
                        {
                            if (OSVersion.HasIoPriority)
                            {
                                switch (thandle.GetIoPriority())
                                {
                                    case 0:
                                        ioPriority0ThreadMenuItem.Checked = true;
                                        break;
                                    case 1:
                                        ioPriority1ThreadMenuItem.Checked = true;
                                        break;
                                    case 2:
                                        ioPriority2ThreadMenuItem.Checked = true;
                                        break;
                                    case 3:
                                        ioPriority3ThreadMenuItem.Checked = true;
                                        break;
                                }
                            }
                        }
                        catch
                        {
                            ioPriorityThreadMenuItem.Enabled = false;
                        }
                    }
                }
                catch
                {
                    priorityThreadMenuItem.Enabled = false;
                    ioPriorityThreadMenuItem.Enabled = false;
                }

                try
                {
                    using (ThreadHandle thandle = new ThreadHandle(
                        int.Parse(listThreads.SelectedItems[0].Text), Program.MinThreadQueryRights
                        ))
                    {
                        using (TokenHandle tokenHandle = thandle.GetToken(TokenAccess.Query))
                        {
                            tokenThreadMenuItem.Enabled = true;
                        }
                    }
                }
                catch (WindowsException)
                {
                    tokenThreadMenuItem.Enabled = false;
                }
            }
            else
            {
                menuThread.DisableAll();

                terminateThreadMenuItem.Enabled = true;
                forceTerminateThreadMenuItem.Enabled = true;
                suspendThreadMenuItem.Enabled = true;
                resumeThreadMenuItem.Enabled = true;
                terminateThreadMenuItem.Text = "&Terminate Threads";
                forceTerminateThreadMenuItem.Text = "Force Terminate Threads";
                suspendThreadMenuItem.Text = "&Suspend Threads";
                resumeThreadMenuItem.Text = "&Resume Threads";
                copyThreadMenuItem.Enabled = true;
            }

            if (listThreads.Items.Count == 0)
            {
                selectAllThreadMenuItem.Enabled = false;
            }
            else
            {
                selectAllThreadMenuItem.Enabled = true;
            }
        }
Esempio n. 2
0
        private void menuThread_Popup(object sender, EventArgs e)
        {
            switch (this.listThreads.SelectedItems.Count)
            {
                case 0:
                    return;
                case 1:
                    this.menuThread.EnableAll();
                    this.terminateThreadMenuItem.Text = "&Terminate Thread";
                    this.forceTerminateThreadMenuItem.Text = "Force Terminate Thread";
                    this.suspendThreadMenuItem.Text = "&Suspend Thread";
                    this.resumeThreadMenuItem.Text = "&Resume Thread";
                    this.priorityThreadMenuItem.Text = "&Priority";
                    this.timeCriticalThreadMenuItem.Checked = false;
                    this.highestThreadMenuItem.Checked = false;
                    this.aboveNormalThreadMenuItem.Checked = false;
                    this.normalThreadMenuItem.Checked = false;
                    this.belowNormalThreadMenuItem.Checked = false;
                    this.lowestThreadMenuItem.Checked = false;
                    this.idleThreadMenuItem.Checked = false;
                    this.ioPriority0ThreadMenuItem.Checked = false;
                    this.ioPriority1ThreadMenuItem.Checked = false;
                    this.ioPriority2ThreadMenuItem.Checked = false;
                    this.ioPriority3ThreadMenuItem.Checked = false;
                    try
                    {
                        using (var thandle = new ThreadHandle(int.Parse(this.listThreads.SelectedItems[0].SubItems[0].Text), Program.MinThreadQueryRights))
                        {
                            try
                            {
                                switch (thandle.GetBasePriorityWin32())
                                {
                                    case ThreadPriorityLevel.TimeCritical:
                                        this.timeCriticalThreadMenuItem.Checked = true;
                                        break;
                                    case ThreadPriorityLevel.Highest:
                                        this.highestThreadMenuItem.Checked = true;
                                        break;
                                    case ThreadPriorityLevel.AboveNormal:
                                        this.aboveNormalThreadMenuItem.Checked = true;
                                        break;
                                    case ThreadPriorityLevel.Normal:
                                        this.normalThreadMenuItem.Checked = true;
                                        break;
                                    case ThreadPriorityLevel.BelowNormal:
                                        this.belowNormalThreadMenuItem.Checked = true;
                                        break;
                                    case ThreadPriorityLevel.Lowest:
                                        this.lowestThreadMenuItem.Checked = true;
                                        break;
                                    case ThreadPriorityLevel.Idle:
                                        this.idleThreadMenuItem.Checked = true;
                                        break;
                                }
                            }
                            catch
                            {
                                this.priorityThreadMenuItem.Enabled = false;
                            }

                            try
                            {
                                if (OSVersion.HasIoPriority)
                                {
                                    switch (thandle.GetIoPriority())
                                    {
                                        case 0:
                                            this.ioPriority0ThreadMenuItem.Checked = true;
                                            break;
                                        case 1:
                                            this.ioPriority1ThreadMenuItem.Checked = true;
                                            break;
                                        case 2:
                                            this.ioPriority2ThreadMenuItem.Checked = true;
                                            break;
                                        case 3:
                                            this.ioPriority3ThreadMenuItem.Checked = true;
                                            break;
                                    }
                                }
                            }
                            catch
                            {
                                this.ioPriorityThreadMenuItem.Enabled = false;
                            }
                        }
                    }
                    catch
                    {
                        this.priorityThreadMenuItem.Enabled = false;
                        this.ioPriorityThreadMenuItem.Enabled = false;
                    }
                    try
                    {
                        using (ThreadHandle thandle = new ThreadHandle(int.Parse(this.listThreads.SelectedItems[0].Text), Program.MinThreadQueryRights))
                        using (TokenHandle tokenHandle = thandle.GetToken(TokenAccess.Query))
                        {
                            this.tokenThreadMenuItem.Enabled = true;
                        }
                    }
                    catch (WindowsException)
                    {
                        this.tokenThreadMenuItem.Enabled = false;
                    }
                    break;
                default:
                    this.terminateThreadMenuItem.Enabled = true;
                    this.forceTerminateThreadMenuItem.Enabled = true;
                    this.suspendThreadMenuItem.Enabled = true;
                    this.resumeThreadMenuItem.Enabled = true;
                    this.terminateThreadMenuItem.Text = "&Terminate Threads";
                    this.forceTerminateThreadMenuItem.Text = "Force Terminate Threads";
                    this.suspendThreadMenuItem.Text = "&Suspend Threads";
                    this.resumeThreadMenuItem.Text = "&Resume Threads";
                    this.copyThreadMenuItem.Enabled = true;
                    break;
            }

            if (listThreads.Items.Count == 0)
            {
                selectAllThreadMenuItem.Enabled = false;
            }
            else
            {
                selectAllThreadMenuItem.Enabled = true;
            }
        }