CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2004
    Posts
    429

    Question Waiting for a process to end? [VS9 C++]

    On my system there is an application (App.exe) that runs, but sometimes it terminates (gracefully and expectantly). At the same time I have another application that, when App.exe is stopped, needs to perform certain tasks. So I need a way to monitor App.exe from my application.

    Something like the following is what I am trying to accomplish
    Code:
    If (App.exe is running wait 360 seconds for it to terminate)
       if (App.exe is not running anymore)
          do the work I need to do when App.exe is NOT running
    So, they KEY is:
    - how do I evaluate if App.exe is running
    - how do I wait 360 seconds for it to close (if it is still running)

    Now this is not very difficult if my Application is the onw that started/spwaned App.exe (using CreateProcess and WaitForExit stuff), but in this case I am not the controlling agent ... so how do I monitor to see if App.exe is still running and consequently wait (for period of time X) for it to end before doing something specific?

    Any hints, help, or recommendantions would be much appreciated.
    Thanks,

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: Waiting for a process to end? [VS9 C++]

    App.exe can create a named kernel object (e.g. mutex). The watching app creates its own object with the same name. If App.exe is running (i.e. object already exists), the watching app can wait on the handle. Waking on the handle means the object has been dismissed by App.exe, which means the app got closed.

    In case there is enough rights for watching app to open process handle, the app can look up for App.exe process id, open App.exe process handle and wait on it in the same manner.
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured