代码之家  ›  专栏  ›  技术社区  ›  Niklas Winde

检查流程的状态

  •  7
  • Niklas Winde  · 技术社区  · 17 年前

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

    2 回复  |  直到 17 年前
        1
  •  11
  •   Student for Life    17 年前

    您需要的一切都在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();
            }
        }
    }
    
        2
  •  0
  •   bugmagnet    17 年前
    推荐文章