c# - Deallocate resources on process termination -


kills the process when I can destroy resources, for example, Task Manager? Is there a way to call a function before the process is closed?

There is not really anything that you can do if your process is defined as one killed, one The process is to kill - the kill process does not get the opportunity to run any code. It is "very much by design"

Imagine you can register the routine that was told when your process was killed by the user (or the second process). what would it be? All other threads in your process will be in an uncertain state, how will you synchronize with them? Remember, the idea is that the process needs to be killed.

The other scenario is also difficult: your code is gentle and trying to do the right thing - eg Clean up and become a good system citizen. There is no code. Imagine what would be a boon for the malware writer if the OS was killed, that code would be allowed to run the code. It would be very bad for malicious processes that were running with standard user privileges, and totally awesome to run with administrative privileges.

The serious final form and structured exception handling will not solve this fundamental issue.

On the top, the OS kills your resources, such as memory and kernel objects, will free all resources. They will not leak but Explorer does not know about your process, so it can not be cleared for this.

One way to resolve this should be a monitoring process that keeps track of your other processes and clears for it. You can do this with a simple process or service. You can also consider any type of shell extension, which did the same thing on its own thread.


Comments