Mike,
Post by Mike WarrenI made it a bit faster while I was at it. It is now set to restart the
watched program after about 2 seconds. Watchdog.exe runs at very low
priority (IDLE_PRIORITY_CLASS, THREAD_PRIORITY_IDLE) so may take a bit
longer on a busy machine.
Since you dug into the API calls here, a suggestion..
How are you watching on the processed being launched?
If you launch the process with CreateProcess or ShellExecute[Ex] then just don't close the process handle but wait until it (the
handle) signals back. Something like WaitForSingleObject(hProcess,INFINITE) will do it. If process handle signals, you can launch
the command line again (in a loop).
Assuming you didn't have any other logic implemented in that watchdog app, you wouldn't have to worry about the process or thread
priorities.
Also, typically for a watchdog app I don't implement window or window proc. There is no need to make such app heavier with the
window queue added. If you want to keep a way how to close the app, then just create a named mutex/event/semaphore at the first
place in WinMain call and, if already exists, signal another sync object back to the first instance of the app to close it. All it
takes is to replace the WaitForSingleObject call above by the WaitForMultipleObject.
--
=========
Regards,
KM