URGENT: Trapping a Kill-Task exception
Author |
Message |
Paris Theofanidi #1 / 8
|
 URGENT: Trapping a Kill-Task exception
I assume that alike in unix, when the user in any-way kills a proccess, that proccess receives an exception. My question is, how do i trap and identify this exception? Thanks.
|
Fri, 28 Jun 2002 03:00:00 GMT |
|
 |
Erik Funkenbusc #2 / 8
|
 URGENT: Trapping a Kill-Task exception
You assume wrong.
Quote: > I assume that alike in unix, when the user in any-way kills a proccess, that > proccess receives an exception. My question is, how do i trap and identify > this exception? > Thanks.
|
Fri, 28 Jun 2002 03:00:00 GMT |
|
 |
Ben Hutchin #3 / 8
|
 URGENT: Trapping a Kill-Task exception
: I assume that alike in unix, when the user in any-way kills a proccess, that : proccess receives an exception. My question is, how do i trap and identify : this exception? If it's a windowing application, your main window will get a WM_CLOSE message (which may be caused by other things). If it's a console application, use SetConsoleCtrlHandler to install a handler for break events (or to ignore them completely). -- Any opinions expressed are my own and not necessarily those of Laser-Scan.
|
Fri, 28 Jun 2002 03:00:00 GMT |
|
 |
Ron Rubl #4 / 8
|
 URGENT: Trapping a Kill-Task exception
Quote:
>: I assume that alike in unix, when the user in any-way kills a proccess, that >: proccess receives an exception. My question is, how do i trap and identify >: this exception? >If it's a windowing application, your main window will get a WM_CLOSE >message (which may be caused by other things). >If it's a console application, use SetConsoleCtrlHandler to install a >handler for break events (or to ignore them completely).
Also note that console apps aren't given the option of refusing to close. If a console app returns false from the handler function or fails to respond, the user will be given a dialog box asking if they want to terminate the app. If your intent is to prevent the user from shutting down the application rather than cleaning up gracefully, this isn't the way to do it. Exactly how to do it depends on what sort of app this is, and what it will be doing. A kiosk type application, for example has different requirements than a background service that shouldn't be ended. Also, it's different in NT than 95/98. Post again with more details if you need to.
|
Fri, 28 Jun 2002 03:00:00 GMT |
|
 |
Paris Theofanidi #5 / 8
|
 URGENT: Trapping a Kill-Task exception
I've tried WM_CLOSE, but it didn't work. I'm talking about a windows application In-fact, when a kill-task occures, non of the objects are being destroyed. My objective is to know when a user kills the application, so that i can take some appropriate actions.
Quote:
> >: I assume that alike in unix, when the user in any-way kills a proccess, > that > >: proccess receives an exception. My question is, how do i trap and > identify > >: this exception? > >If it's a windowing application, your main window will get a WM_CLOSE > >message (which may be caused by other things). > >If it's a console application, use SetConsoleCtrlHandler to install a > >handler for break events (or to ignore them completely). > Also note that console apps aren't given the option of refusing to > close. If a console app returns false from the handler function > or fails to respond, the user will be given a dialog box asking > if they want to terminate the app. > If your intent is to prevent the user from shutting down the application > rather than cleaning up gracefully, this isn't the way to do it. Exactly > how to do it depends on what sort of app this is, and what it will > be doing. A kiosk type application, for example has different > requirements than a background service that shouldn't be ended. > Also, it's different in NT than 95/98. > Post again with more details if you need to.
|
Sat, 29 Jun 2002 03:00:00 GMT |
|
 |
Ron Rubl #6 / 8
|
 URGENT: Trapping a Kill-Task exception
Quote:
>I've tried WM_CLOSE, but it didn't work. >I'm talking about a windows application >In-fact, when a kill-task occures, non of the objects are being destroyed. >My objective is to know when a user kills the application, so that i can >take some appropriate actions.
Are you cleaning up before calling DefWindowProc? If this doesn't help, post some code. From the MSDN Help: "WM_CLOSE The WM_CLOSE message is sent as a signal that a window or an application should terminate. Return Values If an application processes this message, it should return zero. Remarks An application can prompt the user for confirmation, prior to destroying a window, by processing the WM_CLOSE message and calling the DestroyWindow function only if the user confirms the choice. By default, the DefWindowProc function calls the DestroyWindow function to destroy the window."
|
Sat, 29 Jun 2002 03:00:00 GMT |
|
 |
Ben Hutchin #7 / 8
|
 URGENT: Trapping a Kill-Task exception
: I've tried WM_CLOSE, but it didn't work. : I'm talking about a windows application : In-fact, when a kill-task occures, non of the objects are being destroyed. : My objective is to know when a user kills the application, so that i can : take some appropriate actions. <snip> If a task does not respond to a WM_CLOSE message within a certain time (seems to be 10 seconds; this may be tunable) then it is assumed to have encountered a bug and to be unable to shut down cleanly. This is when the user is asked whether to Wait or End Task. If they End Task then the task does not get a chance to respond - because, as I said, it is assumed to be unable to shut down cleanly! Therefore you should make sure to check for messages regularly, and do time-consuming operations in a separate thread from that dealing with messages (or possibly in a separate task). -- Any opinions expressed are my own and not necessarily those of Laser-Scan.
|
Sat, 29 Jun 2002 03:00:00 GMT |
|
 |
Paris Theofanidi #8 / 8
|
 URGENT: Trapping a Kill-Task exception
There's no such problem... the app. runs ok. However, lets say that a user suddenly decides to kill tha application using the Task Manager. I run a check for all the Windows messages sent while i kill the application using the TaskManager.
Quote:
> : I've tried WM_CLOSE, but it didn't work. > : I'm talking about a windows application > : In-fact, when a kill-task occures, non of the objects are being destroyed. > : My objective is to know when a user kills the application, so that i can > : take some appropriate actions. > <snip> > If a task does not respond to a WM_CLOSE message within a certain time > (seems to be 10 seconds; this may be tunable) then it is assumed to > have encountered a bug and to be unable to shut down cleanly. This is > when the user is asked whether to Wait or End Task. If they End Task > then the task does not get a chance to respond - because, as I said, > it is assumed to be unable to shut down cleanly! Therefore you should > make sure to check for messages regularly, and do time-consuming > operations in a separate thread from that dealing with messages (or > possibly in a separate task). > -- > Any opinions expressed are my own and not necessarily those of Laser-Scan.
|
Tue, 02 Jul 2002 03:00:00 GMT |
|
|
|