Click here to Skip to main content
15,903,388 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hi i am getting error like "Cannot process request because the process (2808) has exited"

my code is

C#
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
Posted
Updated 14-Mar-19 20:01pm
Comments
Nicholas Marty 20-Nov-13 5:22am    
Could it be that during your "Thread.Sleep" call the Process terminated all by itself?
agent_kruger 20-Nov-13 5:45am    
are you recieving the problem in "Process.Kill();"
ZurdoDev 20-Nov-13 7:57am    
Where does the error happen?
Sergey Alexandrovich Kryukov 20-Nov-13 12:03pm    
Don't you see that your Thread.Sleep(5000) waiting for who-knows-what and killing a proces is already a big flaw? The whole idea much be wrong, but first you should explain it.
Normally, processes should not be killed, in worst case, they should receive a signal to terminate and exit by themselves. Kill is an indication of unresolved problem solved in emergency style.
—SA

1 solution

C#
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();
                }
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900