I am using a 3rd party class, Table, that represent a database table. The class has a Close() method and it implements IDispose.
I find that calling Close() many times on such a table is fine. Likewise calling Dispose() many times is also fine.
However if I call Dispose() I can not call Close() again or I will get a ObjectDisposedException.
I want to use such a Table as a private member variable in a class.
Samples from the provider of the Table class do not call Dispose() on the table. However since calling Dispose() followed by Close() causes a crash I take it that Dispose() does a full cleanup?
I therefore conclude that I must call Close() followed by Dispose() once and only once?
What is the best way to achieve this? Should I let my class implement IDispose and use the Dispose pattern with a bool disposed_ variable that ensures that the cleanup is only done once + a GC.SuppressFinalize in the Dispose method?
I have already implemented this pattern and understand how it works.
However I am baffled on how complex this is. I would think that C# code would be simpler than C++.
Is there another simpler/better way to do this?