当另一个程序关闭时,应用程序会自行关闭吗? [英] application closes itself when another program closes?

查看:23
本文介绍了当另一个程序关闭时,应用程序会自行关闭吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我有我的监视器"并且我正在玩并且可执行文件是Game.exe"(Rpg Maker xp).我希望我的监视器"在 Game.exe 被杀死或终止后自行关闭.如果可以,我应该如何正确执行此操作?对不起可怕的英语

Basically I have my "monitor" and I'm playing and the executable is "Game.exe" (Rpg Maker xp). I want my "monitor" to close itself after Game.exe is killed or terminated. If I can, how should I do this properly? Sorry horrible english

推荐答案

您可以使用 Process.GetProcessesByName 以确定您的目标进程"是否仍在运行:

You can use Process.GetProcessesByName to find out whether your "target process" is still running:

Dim gameStillRunning = Process.GetProcessesByName("Game").Any()

如何触发你自己的应用程序的结束取决于你的监控应用程序的性质:

How to trigger the end of your own application depends on the nature of your monitoring application:

  • 如果是 GUI 应用程序,请设置一个计时器,经常检查游戏是否仍在运行.

  • If it's a GUI application, set a timer that frequently checks if Game is still running.

如果您的应用程序除了等待游戏关闭之外没有其他用途(或者您有专门的线程用于此目的),您可以使用 p.WaitForExit() 关于进程pGetProcessesByName 获取.

If your application has no other purpose than to wait until Game has been closed (or if you have a dedicated thread for this purpose), you can use p.WaitForExit() on the process p obtained by GetProcessesByName.

这篇关于当另一个程序关闭时,应用程序会自行关闭吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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