从Windows服务关闭一个子进程 [英] Close a child process from a windows service

查看:315
本文介绍了从Windows服务关闭一个子进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了启动其在后台运行其他不同(子)进程在C#中的服务。我怎样才能在一个优雅的方式结束一个进程? Process.kill()不是一个选项, Process.CloseMainWindow()不起作用,因为子进程不可见的(也不应该有任何)。

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) .

坦克对您有所帮助。

推荐答案

如果你控制的其他过程中,你可以使用WCF进程之间的通信,子进程应检查并询问服务是否是时候结束进程,然后子进程做关闭并执行所需的清理。这是一个干净,简单的例子

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.switchonthe$c$c.com/tutorials/wcf-tutorial-basic-interprocess-communication

这篇关于从Windows服务关闭一个子进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆