启动一个从属进程

发布于 2024-12-08 15:24:39 字数 97 浏览 2 评论 0原文

我想使用 Process.Start() 从我的应用程序启动一个进程,并且我希望在我的应用程序崩溃或用户关闭它的情况下,子进程会自动终止。

有可能获得这样的东西吗?

I would like to start a process from my application with Process.Start() and I would like that in case of my app crash or the user close it then the child process is automatically killed.

Is it possible to obtain something like this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初心 2024-12-15 15:24:39

您可以使用 AppDomain.ProcessExit 事件来捕获进程即将退出的时间并让它终止其他进程。我不确定它如何响应未处理的异常,因此您可能必须使用 AppDomain.UnhandledException 并让它使用 FailFast 来处理任何正常异常。作为该处理程序的一部分,您也可以让它杀死其他进程。

You can use the AppDomain.ProcessExit event to catch when your process is about to exit and have it kill the other process. I am unsure as to how it works in reaction to an unhandled exception, so you may have to use AppDomain.UnhandledException and have it use FailFast to handle any normal exceptions. As part of that handler, you have it kill the other process too.

埋情葬爱 2024-12-15 15:24:39

您可以将启动的子进程的 PID 存储在某处,然后在应用程序关闭事件中使用该 PID 终止进程。尽管在未处理的崩溃的情况下,子进程可能会保留在内存中。

You could store PID of lauched child process somewhere, then kill process with that PID in application closing event. Though in case of unhandled crash the child process may retain in memory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文