0

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 :

enter image description here

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.

Skary
  • 1,322
  • 1
  • 13
  • 40
  • would this help? - https://stackoverflow.com/questions/474679/capture-console-exit-c-sharp – yob Sep 22 '21 at 14:14
  • @yob : i really don't know, i do few test and tell you. What i don't know is how windows scheduler try to stop "gracefully" a process; and so how to intercept that signal. – Skary Sep 22 '21 at 14:17

0 Answers0