如何监控另一个应用程序,直到它关闭? [英] How do you monitor another application until it closes?

查看:341
本文介绍了如何监控另一个应用程序,直到它关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有两个可执行文件。一个是我的,另一个是其他应用程序。现在,如果其他应用程序正在运行,我想让我的应用程序运行,直到另一个退出或停止。

Suppose there are two executables. One is mine and the other is some other application. Now if the other app is running, I want my app to run until the other one exits or is stopped.

推荐答案

单独的服务似乎相当过分。

Writing a separate service seems quite an overkill.

您可以先获取一个Process对象,比如通过Process.GetProcessesByName,或者更好 - 使用你想要监视的进程的ProcessID(如果有的话)。然后,您可以尝试从中获取WaitHandle,如例如这里,然后调用WaitOne(或WaitAll,如果你监视几个实例)。

You can first obtain a Process object - say by Process.GetProcessesByName, or better - use the ProcessID of the process you wish to monitor, if you have it. You can then try obtaining a WaitHandle from it, as discussed e.g. here, then call WaitOne on it (or WaitAll, if you're monitoring several instances).

这篇关于如何监控另一个应用程序,直到它关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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