如何在没有进程的情况下终止进程已经退出 [英] How to kill a process without process has exited

查看:84
本文介绍了如何在没有进程的情况下终止进程已经退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我收到的错误如无法处理请求,因为进程(2808)已退出



我的代码是



hi i am getting error like "Cannot process request because the process (2808) has exited"

my code is

try
                {
                    Process[] open_procs = Process.GetProcessesByName("WINWORD");
                    if (open_procs.Length > 0)
                    {
                        foreach (var proc in open_procs)
                        {

                            if (!proc.HasExited)
                            {
                                // Discard cached information about the process.
                                Thread.Sleep(5000);
                                proc.Kill();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                }
                catch (Exception ex)
                {
                    using (StreamWriter w = File.AppendText(@"C:\\Error.txt"))
                    {
                        w.WriteLine("Error occured on " + DateTime.Now.ToString() + "\t" + " In Process , Error Description \n " + ex.ToString());
                    }
                }







任何人都可以看到此问题




can anyoone see this issue

推荐答案

Process[]  runingProcess= Process.GetProcesses();
             for (inti=0; i<runingProcess.Length; i++)
            { 
                 // compare equivalent process by their name
                 if(runingProcess[i].ProcessName=="mspaint")
                {
                     // kill  running process
                    runingProcess[i].Kill();
                }


这篇关于如何在没有进程的情况下终止进程已经退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆