I've been trying to work out how a console program can be notified that it is being terminated, and gracefully handle it.
This seems pretty straight forward for most situations (e.g. killing from Task Manager tries to send a CTRL_CLOSE_EVENT first, which can be handled in a number of ways)
However, when terminating a console program running through Task Scheduler (using Right Click => End) it doesn't seem to raise any of the normal events, even callbacks set through SetConsoleCtrlHandler (which does trigger when terminated from Task Manager).
What is the process that Task Scheduler uses to terminate tasks, and are there any events that can be subscribed to that will be raised when this happens?