I was recently pushed towards SafeHandles in 2.0 to solve the problems I was having in 1.1. Don't like the idea of porting all my code to 2.0 for a fix but ...
One question I have in my mind as I am a tinkerrer (I refuse to use something unless I understand how it works). (It all seems very similar to handleref or various handleprotecter classes in 1.1 as well)
SafeFileHandle sfhIn = new SafeFileHandle(GetStdHandle(STD_INPUT_HANDLE), false);
this code is functionally equivalent to ..
1 IntPtr foo =GetStdHandle(STD_INPUT_HANDLE);
2 SafeFileHandle sfhIn = new SafeFileHandle(foo, false);
If the thread is aborted do I still not run the risk of having never created a SafeFileHandle object to encapsulate my handle which is only being held in the local?
Also it is important to note that there is also a lighter weight version of safehandle ... criticalhandle which does not perform reference counting.
Useful Resources:
http://blogs.msdn.com/shawnfa/archive/2004/08/12/213808.aspx
http://blogs.msdn.com/cbrumme/archive/2004/02/20/77460.aspx
http://msdn2.microsoft.com/en-us/library/system.runtime.constrainedexecution.criticalfinalizerobject.aspx
I will be spending quite some time reading up on the reliability contract sections ... quite interesting!
update: makes alot more sense now. I will try to get out and article on some of this stuff in the near future.