Tommaso Caldarola said:
How to I catch task manager killing application event
or accidentally switching off the computer?
Define "catch". As has been mentioned, there's no way to "catch" events
like that in the sense that you handle them as they happen.
However, if what you want is to *detect* the situation after the fact so you
can try to clean up, you can use the same mechanism a variety of other
software uses, including Windows. That is, create some temporary stored
object (like a file or a registry key, for example) that you delete when you
exit normally. When your program runs, it checks for that object and if the
object is still present, your program was not able to exit normally (which
could be due to the task being killed, or the computer being switched off,
for example).
Pete