当前位置: 首页>>代码示例>>C#>>正文


C# ProcessHandle.IsCritical方法代码示例

本文整理汇总了C#中ProcessHandle.IsCritical方法的典型用法代码示例。如果您正苦于以下问题:C# ProcessHandle.IsCritical方法的具体用法?C# ProcessHandle.IsCritical怎么用?C# ProcessHandle.IsCritical使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProcessHandle的用法示例。


在下文中一共展示了ProcessHandle.IsCritical方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Prompt

        private static bool Prompt(IWin32Window window, int[] pids, string[] names, 
            string action, string content, bool promptOnlyIfDangerous)
        {
            if (!Settings.Instance.WarnDangerous)
                return true;

            string name = "the selected process(es)";

            if (pids.Length == 1)
                name = names[0];
            else
                name = "the selected processes";

            bool dangerous = false;

            foreach (int pid in pids)
            {
                if (PhUtils.IsDangerousPid(pid))
                {
                    dangerous = true;
                    break;
                }
            }

            bool critical = false;

            foreach (int pid in pids)
            {
                try
                {
                    using (var phandle = new ProcessHandle(pid, ProcessAccess.QueryInformation))
                    {
                        if (phandle.IsCritical())
                        {
                            critical = true;
                            break;
                        }
                    }
                }
                catch
                { }
            }

            if (promptOnlyIfDangerous && !dangerous && !critical)
                return true;

            DialogResult result = DialogResult.No;

            if (OSVersion.HasTaskDialogs)
            {
                TaskDialog td = new TaskDialog();

                td.WindowTitle = "Process Hacker";
                td.MainInstruction = "Do you want to " + action + " " + name + "?";
                td.Content = content;

                if (critical)
                {
                    td.MainIcon = TaskDialogIcon.Warning;
                    td.Content = "You are about to " + action + " one or more CRITICAL processes. " +
                        "Windows is designed to break (crash) when one of these processes is terminated. " +
                        "Are you sure you want to continue?";
                }
                else if (dangerous)
                {
                    td.MainIcon = TaskDialogIcon.Warning;
                    td.Content = "You are about to " + action + " one or more system processes. " +
                        "Doing so will cause system instability. Are you sure you want to continue?";
                }

                if (pids.Length > 1)
                {
                    td.ExpandFooterArea = true;
                    td.ExpandedInformation = "Processes:\r\n";

                    for (int i = 0; i < pids.Length; i++)
                    {
                        bool dangerousPid, criticalPid;

                        dangerousPid = PhUtils.IsDangerousPid(pids[i]);

                        try
                        {
                            using (var phandle = new ProcessHandle(pids[i], ProcessAccess.QueryInformation))
                                criticalPid = phandle.IsCritical();
                        }
                        catch
                        {
                            criticalPid = false;
                        }

                        td.ExpandedInformation += names[i] + " (PID " + pids[i].ToString() + ")" + 
                            (dangerousPid ? " (system process) " : "") +
                            (criticalPid ? " (CRITICAL) " : "") +
                            "\r\n";
                    }

                    td.ExpandedInformation = td.ExpandedInformation.Trim();
                }

//.........这里部分代码省略.........
开发者ID:andyvand,项目名称:ProcessHacker,代码行数:101,代码来源:ProcessActions.cs


注:本文中的ProcessHandle.IsCritical方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。