What program?
This sounds like you need a wrapper script that can monitor the task and perform operations against it. It's pretty easy to do.
Also, you can specify in the task schuduler that if it's still running after X minutes or hours, to stop it.