1

I'm trying to kill a service process after I'm stopping the service, The service is going down very slow - something like 7 seconds, the program kill the process by the process id but it gets ArgumentException when I'm trying to do that with command line it still show me that the process is running though I need to kill it with /F (force) what am I missing?

    public void KillService(uint processID)
    {
     try
        {                
            process = Process.GetProcessById((int)processID);
            if (process != null)
            {
                process.Kill(); 

            }                                                                
        }
        catch (ArgumentException)
        {
            // Thrown if the process specified by processID
            // is no longer running.               
        }
        catch (Win32Exception)
        {
            // Thrown if process is already terminating,
            // the process is a Win16 exe or the process
            // could not be terminated.

        }
        catch (InvalidOperationException)
        {
            // Thrown if the process has already terminated.

        }
   }
ishigh
  • 31
  • 1
  • 1
  • 7
  • Have you tried killing `process tree` i.e. Process and its children? I have found this http://stackoverflow.com/questions/5901679/kill-process-tree-programatically-in-c-sharp – Hassan Apr 22 '14 at 12:09
  • @Hassan Thanks for the reply, I did it already, it is only one process anyway... – ishigh Apr 22 '14 at 12:27
  • You can check `process.HasExited` first to prevent any exceptions. – Nick Apr 22 '14 at 12:35
  • @Nick Thansk, though I want to catch the exceptions for log purposes :-) – ishigh Apr 22 '14 at 12:37

0 Answers0