I have written a simple console program that is scheduled and executed by Windows Task Scheduler. Sometimes this program take longer than expected so i have configured the TaskScheduler Settings to stop the task if it takes more than 1h to complention :
My task is also configured not to run concurrently, so if an execution take longer to complete the next schedule is delayed (eg : task is scheduled each 15 minutes but sometimes will take more than 1 hour till the killing point).
My question is, when execution take logner than 1 hour, i suppose TaskScheduler will send a signal to process to stop and then try to kill it (the second chekmark in my picture, below the selected one). How can i intercept the first signal in my console program? I would like try to suspend execution so that the kill have not to happen.
I have "critical" region in my code, and a kill in that region may "corrupt" DB data, i would like to intercept the request to terminate and then comply (even if the work is not complete). In my scenario is better a job not done than one inconsistently done.