Close a child process from a windows service

戏子无情 提交于 2019-12-11 10:41:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!