.NET 判断进程是否运行 是否未响应

//cx为要判断的进程名的字符串数组

int i = 0;

            string aa="";

            System.Net.IPAddress[] _IPList = System.Net.Dns.GetHostAddresses(Dns.GetHostName());

            for (int j = 0; j != _IPList.Length; j++)

            {

                if (_IPList[j].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)

                {

                    aa=_IPList[j].ToString()+"||";

                }

            }

            string ss = "computername:" + Dns.GetHostName() + "\rIP:" + aa + "\r";

                Process[] arrayProcess = Process.GetProcesses();

                Process[] ppp;

                foreach(string pn in cx){

                  //  MessageBox.Show(pn);

                        ppp = Process.GetProcessesByName(pn);

                        if (ppp.Length <= 0)

                        {

                            i = 1;

                            ss += con(pn) + " process is not running" + "\r";

                        }

            }

                foreach (Process process in arrayProcess)

                {

                    if(Array.Exists(cx, element => element == process.ProcessName))

                    {

                        //MessageBox.Show(process.ProcessName);

                    if (process.Responding == false)

                    {

                        i = 1;

                        ss += con(process.ProcessName) + " process wrong" + "\r";


                    }

                }

            }


            if (i == 0) {

                ss += "all of processes are normal";

            }

            return ss;

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容