Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do something before process get killed in windows

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,

like image 846
Frank Avatar asked Oct 21 '25 18:10

Frank


2 Answers

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.

like image 111
Tayyab Avatar answered Oct 23 '25 09:10

Tayyab


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).

like image 38
Mark Sowul Avatar answered Oct 23 '25 08:10

Mark Sowul