问题
I've written a service in c# that starts different other (child)processes which run in background. How can I close a process in a graceful way? Process.kill()
is not an option, and Process.CloseMainWindow()
does not work because the child process has no visible window (and shouldn't have any) .
Tanks for your help.
回答1:
If you control that other process you can use WCF to communicate between processes, child process should check and ask service if is time to end process and then child process can do close and do needed cleanup. Here is a clean and simple example
http://www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication
回答2:
You can use WMI to do this(if that is an option). Look at the examples below: http://www.codeproject.com/KB/cs/EverythingInWmi02.aspx
来源:https://stackoverflow.com/questions/6813184/close-a-child-process-from-a-windows-service