Your only chance is to use the Dispose pattern and propagate it down your object graph(s), and additionally use try/catch logic in the appropriate places. Finalizers for sure will lead you nowhere since - as stated above - they are indeterministic in order. The logic may become complicated depending on what you are doing - but there has to be one.
HosamAly wrote:
Another issue is when the application is rudely unloaded;
If that means 'crash' or 'cancelling the app via task manager' there's exactly nothing you can do. (Anyway, this is exceptional and not part of a programs normal behaviour, so you're not really to blame for things that happen in this case.) Regards Thomas
www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software.