1

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

arthur
  • 1,034
  • 2
  • 17
  • 31
  • 1
    If the given program is unresponsive (because of expecting an input from the user), the only thing you can do is killing it (as you are doing). Regarding the child windows, they are managed by the external program itself and thus will be closed when the main program is closed. – varocarbas Aug 07 '13 at 16:31
  • @varocarbas: thanks a lot for the comment. How difficult would be to check weather there are child windows? Is it possible to get the corresponding `Process` of the `Application` nicer (without scaning the whole list of Processes of the System? – arthur Aug 08 '13 at 07:36
  • It is not possible to give a general answer to this question. As said, child windows are managed by the target application and thus their behaviour is determined by it. You can manage child windows via process only if the target application creates a new process per child window (example: Excel with the different instances you open); otherwise, you can only access them via gApp (if allowed to do so). In summary, for this kind of things you have two options: either asking someone with experience in this specific application or doing some trial-and-error/testing. – varocarbas Aug 08 '13 at 08:07

1 Answers1

0

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

Community
  • 1
  • 1
arthur
  • 1,034
  • 2
  • 17
  • 31