Working with C#. I have an abstract class that I use to read/write settings to an xml file. When the class is no longer needed I want to perform one last write operation to the xml file before the class gets disposed. I tried putting this code in a destructor method ~myClass() {} but it throws an exception saying that the safe handle is closed. I am guessing this means that the class is already disposed or partially disposed. So if the destructor is not the correct place to do this where is the correct place? Do I need to implement IDisposable or something?
Working with C#. I have an abstract class that I use to read/write settings
Share
There is no such thing as a
destructors in C#. Please refer to this question’s accepted answer from Jon Skeet who explains and provide a good article on the topic.Sample use of a C# DestructorBesides, perhaps should you consider to implement the
IDisposableinterface in your class so that you could perform your manoeuvre.