I have created a console application (.exe), and we have used SetConsoleCtrlHandler for signal handling i.e. "CTRL + C" and Log Off and Shutdown Events.
We are properly able to handle the "CTRL+C" event but Logoff and Shut down events cannot be handled properly.
Following content is mentioned at MSDN:
The system generates CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, and CTRL_SHUTDOWN_EVENT signals when the user closes the console, logs off, or shuts down the system so that the process has an opportunity to clean up before termination. Console functions, or any C run-time functions that call console functions, may not work reliably during processing of any of the three signals mentioned previously. The reason is that some or all of the internal console cleanup routines may have been called before executing the process signal handler.
Please suggest how we can properly handle Logoff and shutdown event by our console application.
Or please suggest any other technique (if available) for handling the logoff and shutdown event by the console based application.