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 open task manager in windows and kill the excutable? My destructors won't get hit in this case.
Does anybody know a good parttern to solve this? (C#)
Thanks a lot,
You cannot handle the scenario if user kill the application forcefully. But you don't have to worry about the resources. Windows will automatically free the resources acquired by your process when it is killed.
When the process is killed the rug is yanked out from under you. But the process's resources will be killed along with the process, so you don't need to clean them up. Ensuring e.g. file consistency, however, is a significantly more complicated story (similar to if the plug were yanked out).
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