Im currently a little confused regarding the implementation of the Dispose() method in the context of unmanaged resources, in particular database connections. I understand that GC cleans up all object that dont have unmanaged resources. I understand that i can use the using statement to enclose my database connection so that dispose() is automatically closed. what i dont understand is the following:
1) If i need a connection to remain open for longer (ie cant use a using statement) then what would the code be to explicitly close the connection?
2) If i have a dispose() method then i should also include a finalizer in the class declaration. I should also follow the pattern such that if the dispose()method is called before the finalizer then i should call GC.Suppressfinalize(this) method since i would have, assuming i havent screwed up, already disposed of the unmanaged resources. Have i understood this correctly?
3) Are their any limitations/things to keep in mind when a class (aka ClassA) uses a method in another class (aka classB) and classB uses unmanaged resources? Do i need to call a Dispose() method on classA??
1) is the main question so id appreciate it if someone would atleast be willing to answer that.
This post has been edited by scolty: 02 December 2011 - 04:10 AM