C# 检查进程状态

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/320645/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 23:06:34  来源:igfitidea点击:

Check status of process

c#.net

提问by Niklas Winde

I want to programmatically verify the status of an application to see if it has crashed or stopped. I know how to see if the process exists in C# but can I also see if it is "Not responding"?

我想以编程方式验证应用程序的状态,以查看它是否已崩溃或停止。我知道如何查看 C# 中是否存在该进程,但我也可以查看它是否“无响应”?

采纳答案by Student for Life

Everything you need is in System.Diagnostics, for example: to check if a process is responding.

您需要的一切都在 System.Diagnostics 中,例如:检查进程是否正在响应。

using System;
using System.Diagnostics;

namespace ProcessStatus
{
    class Program
    {
        static void Main(string[] args)
        {
            Process[] processes = Process.GetProcesses();

            foreach (Process process in processes)
            {
                Console.WriteLine("Process Name: {0}, Responding: {1}", process.ProcessName, process.Responding);
            }

            Console.Write("press enter");
            Console.ReadLine();
        }
    }
}

回答by bugmagnet

See "Not Responding" Message in Windows Form Applicatiat Fog Creek Software

请参阅Fog Creek Software 的Windows Form Applicati中的“无响应”消息