How does task manager kill my program?

岁酱吖の 提交于 2019-12-01 17:03:46

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?

Yes, these are the options.

For completeness, note that console mode applications get the CTRL_CLOSE_EVENT send that you could react upon, when the "End Task" button is clicked.

Note that you cannot intercept or react upon TerminateProcess. Your process will die and there is nothing you can do before that happens. Actually, it would be pretty bad if you could. Because then there would be no way to terminate a process that went haywire.

When you get a WM_CLOSE, you can easily detect that so your application can act upon it.

I don't believe it's possible to know when TerminateProcess is being called to kill your application. The TerminateProcess documentation says it's an immediate and unconditional shutdown of the target process.

(Depending on how much you want to achieve this, take a look at this link about hooking into the Windows API but don't expect it to be easy.)

Task manager internally uses the EndTask function. This functions sends a WM_CLOSE message to your application. If your application does not respond to that message and the user forces to terminate your Application, TerminateProcess is called on your process.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!