The program does not need to call SetConsoleCtrlHandler() if the only concern is shutdown via DllMain.
If you are going to allow the default handler to call ExitProcess(), then I see no advantage over calling TerminateProcess(). You wouldn't even be able to choose what exit value is returned.
If the OP is hoping to be able to perform some kind of clean up and controlled shutdown, he would need to install his own handler.
The idea way would be to have a thread of the server waiting on an Event, then fire the Event when closedown is needed.
You'd have to expand on that a little. What would be the advantage in having a separate thread?
SetConsoleCtrlHandler() can already handle all of these events:
- CTRL_C_EVENT:
- CTRL_CLOSE_EVENT:
- CTRL_BREAK_EVENT:
- CTRL_LOGOFF_EVENT:
- CTRL_SHUTDOWN_EVENT:
Are you suggesting that the OP should spawn a separate thread that installs handlers and then goes to sleep waiting for them to occur? If so, how would you suggest that it then "interupt" the main thread when they do?
Or are you suggesting creating some kind of user event that this extra thread would wait on? If so, how would the Perl script generate that event? And what would the extra thread do with it when it arrived?
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |
I agree that, all things considered, an Event will be the most appropriate way to handle this.
In my experience, “murder is always messy.” :-D More to the point, “it's never exactly the same way twice.” So, it's very difficult to test.
You might have one thread in the application that does nothing but wait for the closing whistle. It starts-up the app, waits for the whistle, quickly notifies the workers, waits briefly for them to respond, and then closes down the app as neatly as it can manage.
| |
quickly notifies the workers,
How?
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |