Exit code of a process terminated with Process.Kill() in C#
In have 2 processes, a parent process and a child process. The parent process controls the lifecycle of child process i.e. parent process launches the child process when it needs the child to do some work and also it kills the child when it is done with it. To kill the child process, parent process is u开发者_如何学Pythonsing Process.Kill() and process.WaitForExit() APIs.
Questions: -
I am observing that the exit code of the child process is always -1. Who is setting this exit code?
How can I change this exit code?
- Process.Kill
- No. Unless you pinvoke TerminateProcess() yourself, uExitCode argument.
Have a look at Reflector, this kind of stuff is easy to find with it.
The process exit code is likely being set by Win32. You can't change it. If you want to change the exit code, don't use Process.Kill as your IPC mechanism. Set an event or use other IPC primitives instead.
精彩评论