检查过程中的地位过程中、地位

2023-09-04 00:12:19 作者:-君如薄纸一般的脸

我希望以编程方式验证应用程序的状态,看它是否已经崩溃或停止。我知道如何确定进程是否存在,在C#中,但我也可以看到,如果它是没有响应?

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"?

推荐答案

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

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

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();
        }
    }
}