Visual Basic: killing the process of an Application Object

3k views Asked by At

In Visual Basic I create an Application Object and start it:

gApp = New CANoe.Application
gMeasurement = gApp.Measurement
gApp.Open(arrArgs(0), False, False)
gMeasurement.Start()

Once the application finishes processing the data two possible scenarios may happen: (i) the data file was corrupt and (in normal circumstances) an allert window is raised and (ii) the data file was ok. In (ii) case I can quite the Application with gApp.Quit(). However in case (i) gApp.Quit() does not work, since the program expects input from the user (although often I do not see the window at all).

Question 1: how can I quite the process corresponding to gApp? Currently I am quiting this in this way:

        For Each p As Process In Process.GetProcesses
            If p.ProcessName = "CANoe32" Then
                p.Kill()
            End If
        Next

In general this is a bad solution since more instances of CANoe32 may run (although in this particular case only one process of this binary may run on the system).

Question 2 what would be a more elegant solution to quit the gApp in case it has child windows?

Any comments are very helpful

1

There are 1 answers

0
arthur On BEST ANSWER

A possible solution to the problem would to use something similar to this ticket:

how-do-i-get-the-process-id-from-a-created-excel-application-object