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
1
2
3
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,
Well, first you can get the instance of the app.exe by the title of the window and then check to see if it is running once you do! Here is a generic way, you will have to create a loop for it and I would definitely put a 1 second pause in that loop so it is not eating away at your processor!

[code]
char *title = "Put Title Here!";
HWND hWnd = FindWindowA( NULL, title );
DWORD* processID = new DWORD;
GetWindowThreadProcessId(windowHandle, processID);
[\code]

If your processID is 0, then it couldn't be found, else it is running! Here is a link explaining it much better with more code to help!

http://www.cplusplus.com/forum/windows/12137/
Last edited on
Topic archived. No new replies allowed.