从Windows服务关闭一个子进程

编程入门 行业动态 更新时间:2024-10-10 09:24:04
本文介绍了从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

的www.switchonthe$c$c/tutorials/wcf-tutorial-basic-interprocess-communication

更多推荐

从Windows服务关闭一个子进程

本文发布于:2023-11-08 20:52:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1570427.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:个子   进程   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!