我正在创建一个新进程来执行一些长时间运行的操作(pdf文件转换)。问题是,如果我想使用其ID杀死该进程,它不会被杀死,我仍然会在系统进程列表中看到它。为什么?
using (Process p = new Process())
{
p.StartInfo.FileName = "some_file_name";
p.StartInfo.WorkingDirectory = "some_dir";
p.StartInfo.Arguments = fullFilePath;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.UseShellExecute = false;
p.Start();
myProcessID = p.Id;
result.OutputMsg = p.StandardOutput.ReadToEnd(); <-- here it waits until operation completes
result.ErrorMsg = p.StandardError.ReadToEnd();
p.WaitForExit();
}
...
Process p = Process.GetProcessById(myProcessID);
if (p != null)
p.Kill();
好的,我看到它被杀了,但转换仍在继续。我看到还创建了一个名为conhost.exe
(控制台窗口主机)的新进程,但没有其ID。没有它,我无法删除它