Wait for a program and the program it started (launcher app) to exit in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TxAg03
    New Member
    • Feb 2008
    • 14

    Wait for a program and the program it started (launcher app) to exit in C#

    I ran an outside program that launched another program. I created a process for the launcher program and waited for that to exit, but what I need is to have it wait for the 2nd program to exit.

    system.diagnost ics.process instApp = system.diagnost ics.process.sta rt("Setup.exe") ;
    instApp.WaitFor Exit();

    //code that is dependent upon the installation of the above program

    Problem I'm having is that the Setup.exe extracts a few files for the installation process, then launches the actual installer. Once the actual installer is ran, my 'WaitForExit()' thinks it's over. Is there a way to wait for the Setup.exe and any program it launches to exit before executing the next line(s) of code?

    Thank you in advance.
    Jim
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #2
    So let me understand this correctly...

    Your app fires off the some kind of extractor for your installer...the installer then runs but by which time your extractor has finished and triggered your app to continue on before the installer has completed. Consequently the installer process that your application relies on having completed fails?

    Comment

    • TxAg03
      New Member
      • Feb 2008
      • 14

      #3
      Thank you for your quick response balabaster.

      Exactly!!! But how can I test to make sure that the installer and whatever program(s) it launches have finished before continuing in my code? I've been looking into Threads, but not quite sure if that's the correct path to go.

      Any suggestions?

      Comment

      • balabaster
        Recognized Expert Contributor
        • Mar 2007
        • 798

        #4
        Originally posted by TxAg03
        Thank you for your quick response balabaster.

        Exactly!!! But how can I test to make sure that the installer and whatever program(s) it launches have finished before continuing in my code? I've been looking into Threads, but not quite sure if that's the correct path to go.

        Any suggestions?
        I'm guessing what you would need to do is look into processes. In your setup launcher application, have it extract the files and then run the installer. Use the System.Diagnost ics.Process namespace to figure out the process id of the installer and force your setup launcher to remain active until the process with the id of the installer closes. At that point your setup launcher can exit. In your main application you can use your regular WaitForExit() method to wait for your setup launcher to exit.

        Comment

        • TxAg03
          New Member
          • Feb 2008
          • 14

          #5
          I was able to determine the process ID of the launcher program, but am having trouble determining the process ID of the installer it opens. Is there something that can quickly and easily determine if a program starts another program and wait for that 2nd program to finish?

          Comment

          • balabaster
            Recognized Expert Contributor
            • Mar 2007
            • 798

            #6
            Originally posted by TxAg03
            I was able to determine the process ID of the launcher program, but am having trouble determining the process ID of the installer it opens. Is there something that can quickly and easily determine if a program starts another program and wait for that 2nd program to finish?
            Not as far as I'm aware...but I'm sure someone can come up with some ingenious workaround that would give you what you're looking for.

            Comment

            • TxAg03
              New Member
              • Feb 2008
              • 14

              #7
              For those that are interested in the answer, the best solution I was able to find was to get the main program ID and the program ID of the program it launches. Wait for the main program to finish, then wait for the launched program to finish.

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Originally posted by TxAg03
                For those that are interested in the answer, the best solution I was able to find was to get the main program ID and the program ID of the program it launches. Wait for the main program to finish, then wait for the launched program to finish.
                Isn't that what was suggested earlier? How did you end up finding the ID of the 2nd process?
                I'm not sure .NET gives you the ability, but there should have been a parent/child relationship between those two objects. Win32API at very least could be used to find that relationship?

                Comment

                • TxAg03
                  New Member
                  • Feb 2008
                  • 14

                  #9
                  I'm sure there is a much better way to do so, like you mentioned. Being pressed for time, I ran the main exe and in the windows task manager processes, I waited to see what the launcher exe name was. I tried finding a way to get the child ID, but wasn't able to find it.

                  Comment

                  Working...