I've written a daemon console app in c# that is run from Scheduled Tasks. I want to detect when the user right-clicks on the task and does "End Task" in order to do some logging and cleanup.
I'm currently using SetConsoleCtrlHandler to register a callback and this works perfectly on my development XP machine. However, when it is run on our production Windows Server 2003 box, the callback is never fired.
This thread indicates that it may be an issue with Remote Desktop and "Session 0 isolation", but I don't know if that also applies to Windows Server 2003.
Does this function work differently on Windows Server and are there any workarounds for this behavior or alternatives to SetConsoleCtrlHandler for detecting scheduled tasks shutting down?
I know I could switch to a Windows Service architecture, but that has it's own complications and doesn't fit well into my current system.