Hi,

I have a class that runs an external ap using shell then waits till the app is quit before carrying on.

Does anybody know if it is possible to start an app say by clicking a button then be told when the app has closed. The app can be open more than once.

The problem I have is when the code is run everything stops till the app has finished.

Hope this makes sense.

Here is the code I have so far:

Public Function StartAndWait(ByVal ProcessPath As String, ByVal Licence As Integer)
        Dim startProcess As System.Diagnostics.Process
        Try
            startProcess = New System.Diagnostics.Process()
            startProcess.StartInfo.FileName = ProcessPath
            startProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
            startProcess.Start()

            'Wait until the process passes back an exit code 
            startProcess.WaitForExit()

            ' Check Exit code to see if process finished without error.
            If startProcess.ExitCode <> 0 Then
                MessageBox.Show("Exit Code: " & startProcess.ExitCode)
            End If

            'Free resources associated with this process
            startProcess.Close()

            StartAndWait = True

        Catch
            StartAndWait = False
            MessageBox.Show("Could not start process " & ProcessPath, "Error")
        End Try
    End Function

Recommended Answers

All 2 Replies

I would try using Multi-Threading

Make the main thread continue running your application and the NEW Multi-Thread the open the other application

when the application is running the new thread will pause but your main app will continue to run also when the external app is closed the new thread will continue (add a msgbox in the new thread) and then the thread will close

Multi-Threading
http://www.taylorsnet.co.uk/SourceCodeDetail.aspx?SourceID=20

Thanks for your reply. I will give it a go on Monday (work). I'm new to VB.NEt. In the process of moving from VB6.

The link you added looks great as well.

Cheers,
PG

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.