Paulo Paulo - 2 months ago 6
Vb.net Question

application closes itself when another program closes?

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

Answer

You can 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:

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

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