I'm currently writing a class to manage per-user configuration files,
using the same format as the app.config file. This will be used in a
Winforms app to manage user options, window positions, etc. When
instantiated, the object will be available as a service at the
application level.
The question I have is about the most efficient way to manage the
lifetime of the XmlDocument object that contains the XML file itself.
Currently, I do the .Load() the first time the service is called on
and then store it in a protected property of the service. So...
1. Is it more efficient to just open and close the document each time
it's viewed/updated?
2. Is it better to keep it open for the lifetime of the object (which
is also the lifetime of the app domain)?
3. If I keep it open all the time, would it be better if I called
Save() when various changes are made, or just when the object is
shutdown? Both?
4. In terms of an on-disk resource being used as a memory mapped
structure like this, what's the cleanest way to deal with
updating/saving the file at destruction? Put a Save() in Finalize, or
should I go the route of implement IDisposable?
Thanks in advance for any advice/insight on this.
J