Responding to CTRL_CLOSE_EVENT when the application is blocked

From: Krzysztof Zelechowski (krixel_at_WP.PL)
Date: 02/03/04


Date: Tue, 3 Feb 2004 19:02:16 +0100

First let me give some background information to start with. If you attempt
to close the console of your character-mode application, the system presents
a dialog box saying that it cannot be cleanly closed. If you want to close
it in a more user-friendly way, you have handle a CTRL_CLOSE_EVENT the
system generates. You accomplish this by calling
SetConsoleCtrlHandler(ExitOnClose, TRUE);

where ExitOnClose is your handler. The handler gets called in a separate
thread so you can clean up and terminate the process.
My question is: can I choose to notify the other threads of my application
(the main thread, in my case)? It is easy if they have a chance to get that
notification by examining a shared variable. However, this does not work
for me because my application is reading input from the console at that
time. The only solution I have come up with is to close the standard input
handle within the handler. I would like to do it in a more elegant way.
What if it were reading from a local communications device? Performing an
asynchronous read is not a solution because the standard handles are open in
a synchronous mode and the standard cin object which I am using does not
support asynchronous operation. I would like to cause the read operation to
fail in order to unblock the main thread and test for notofication. It is
not possible with signals and exceptions because they all act upon the
current thread (unlike in Unix, where a blocking operation can be
interrupted from outside without killing the whole process altogether).

Any suggestions?
Chris



Relevant Pages

  • Re: Responding to CTRL_CLOSE_EVENT when the application is blocked
    ... > to close the console of your character-mode application, ... The handler gets called in a separate ... The only solution I have come up with is to close the standard ... > support asynchronous operation. ...
    (microsoft.public.win32.programmer.ui)
  • Re: Responding to CTRL_CLOSE_EVENT when the application is blocked
    ... > to close the console of your character-mode application, ... The handler gets called in a separate ... The only solution I have come up with is to close the standard ... > support asynchronous operation. ...
    (microsoft.public.win32.programmer.ui)
  • Re: Responding to CTRL_CLOSE_EVENT when the application is blocked
    ... >> to close the console of your character-mode application, ... >> where ExitOnClose is your handler. ... The only solution I have come up with is to close the standard ... >> current thread (unlike in Unix, where a blocking operation can be ...
    (microsoft.public.win32.programmer.ui)
  • Re: No, POLL and WAIT
    ... > The WaitForSingleObjectEx function returns when one of the following ... Yes, you can wait on a file handle that refers to a console, and yes in many ... > The GetStdHandle function returns a handle for the standard input, ... or by the GetStdHandle function. ...
    (alt.lang.asm)
  • Re: SetConsoleCtrlHandler
    ... I've stressed to the customer they must do extensive testing ... console logoff events. ... This modified handler does not call ... This allows the service to continue running after the user logs ...
    (microsoft.public.win32.programmer.kernel)

Quantcast