我正在尝试在我停止服务后终止一个服务进程,该服务正在下降非常慢 - 类似于7秒,程序通过进程ID终止进程,但是当我遇到它时它会获得ArgumentException试图用命令行做它仍然告诉我进程正在运行虽然我需要用/ F(强制)杀死它 我错过了什么?
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.
}
}