Using SetConsoleCtrlHandler i set a handler that gets called when needed (CTRL_C_EVENT, CTRL_BREAK_EVENT, CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, CTRL_SHUTDOWN_EVENT) [either the RTL or the OS or whatever spawns a high priority worker thread to run it].
The handler signals the apps worker thread to to finish what it is doing and exit. Then it will wait till the main thread signals back that it is safe to exit the handler (which will terminate the process in case of CTRL_CLOSE_EVENT).
All of this works perfectly.
However, there is a long ignored slight problem in the main threads termination code (before signalling the CtrlHandler) which i opted to try to amend today ... and ran into problems.
VS2015 just does not let me debug any of it.
All i can see is the state at breakpoint (which is of limited use) - F11 etc will just instantly terminate the process (debug build of course). At breakpoint i can see that the CtrlHandler thread is waiting in my custom infinite spin-lock as it should ... so, who is killing my process? Can i stop it from doing that (it is not logoff/shutdown, so, what the hell)?
Currently trying to debug by just putting the breakpoint in different places and trying to guess by the visible state what is going on - needless to say, it would help immensely if i could just step through that code.