My program need to occupy some resources. I want it to release those resources before exit. It\'s easy to achieve when the excutable exit normally. However, what if the user
It seems impossible to react to the process being killed. The way to do that would be to use signals but as the doc says (here), the SIGTERM signal is not generated under windows NT.
You could try to PInkoke the signal function and catch SIGINT if your program is a console application and you want to react to ctrl+c.
Like others said, Windows will free up resources for you and the only that is dangerous is that your open files will be left in an unknown state, so it might not be worth the effort.