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.
}
}