Search code examples
vb.netvb.net-2010

Show message box when a specifc program ".exe" open


I`m playing a game which take around 30 sec to load and open , so I decided to create a please wait app for it the app idea is : User click on it then my app will open the game and say please wait label will appear then my app will close its self.

The problem is I don't know how to make my app show message saying "Welcome to XXX " then close when "DMC.exe" open

Thanks ^^


Solution

  • It depends on how "DMC.exe" is written, but the simplest solution would be to try with Process.WaitForInputIdle():

    Causes the Process component to wait indefinitely for the associated process to enter an idle state.

    An "idle state" is often reached once the main window has been displayed and is waiting for user input:

    Public Class Form1
    
        Private P As Process
        Private T As System.Threading.Thread
    
        Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
            P = Process.Start("dmc.exe")
            T = New System.Threading.Thread(AddressOf Wait)
            T.Start()
        End Sub
    
        Private Sub Wait()
            P.WaitForInputIdle()
            Application.Exit()
        End Sub
    
    End Class