I have this MFC program that when I kill it with task manager I get an exception on my program and then it crashes.
I want to get the event from the task manager, when it is going to kill my process and close my program gracefully.
I understand that there are few methods that the task manager is using in order to kill a process.
1) From the applications tab, someone told me it is sending WM_CLOSE message to my application's main visible window, And if my application is not going down after few seconds, the task manager detects it as not-responding and uses TerminateProcess() on its process.
2) From the process tab, someone told me it is using TerminateProcess() windows API.
Is there any other method the Task Manager is using?
Am i right about the last 2 methods?
Thank you in advance.
Yes, both of these are correct. You should respond to WM_CLOSE to close gracefully. This could come from anywhere, not just task manager (shutdown for instance).
MFC normally handles WM_CLOSE. If your app is not responding then your main thread must be sat doing something else, or more likely from your description is crashing somewhere in the WM_CLOSE handler.
Can you debug your app to find where the exception is being raised?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With