问题
I am invoking a command line process from C# that does an update from some remote server. Works fine when it can find the remote server and fetch data from it. Also works fine if not connected to a network.
However, when the remote server is unreachable, the external process will try to fetch data indefinitely, and there is no command line options to specify a timeout. So I added a force kill on the process after trying for 15 seconds.
using (var process = new Process {...})
{
process.Start();
if (!process.WaitForExit(15 * 1000))
{
process.Kill();
}
}
I can see the process being terminated when process.Kill()
is invoked, but then it hangs when exiting the using
scope (i.e. when disposing the process).
What's wrong with this? Am I missing something to make sure this process is properly killed?
Thanks!
EDIT:
Process StartInfo is
FileName = command,
Arguments = arguments,
WorkingDirectory = workDir,
CreateNoWindow = true,
UseShellExecute = false
来源:https://stackoverflow.com/questions/50572800/c-sharp-process-hangs-on-dispose