EDN Admin
Well-known member
My application uses code similar to the following
<div style="color:Black;background-color:White; <pre>
_xml = XElement.Load(XmlFile);
<span style="color:Green; // Manipulate the data...
_xml.Save(XmlFile);
[/code]
to work with xml data (where XmlFile is a reference to the xml path and filename). My question is how can I lock down access to the physical xml file during the load and save operations since multiple apps will be using the component that manipulates
the xml. I currently have:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; lock (<span style="color:Blue; this)
{
<span style="color:Green; // Load or Save...
}
[/code]
But this wont be reliable because even though the class is a Singleton since its getting accessed by multiple executables there will still be multiple instances of the class. Ive been able to do something similar with text files using FileStream
with the access and share parameters, but not sure how to apply this to working with an xml document (ideally Id like to continue using XElement, because changing it to something like XmlDocument would involve an overhaul of the way I have the class designed).
Any help would be appreciated.
Thanks,
-Dave
View the full article
<div style="color:Black;background-color:White; <pre>
_xml = XElement.Load(XmlFile);
<span style="color:Green; // Manipulate the data...
_xml.Save(XmlFile);
[/code]
to work with xml data (where XmlFile is a reference to the xml path and filename). My question is how can I lock down access to the physical xml file during the load and save operations since multiple apps will be using the component that manipulates
the xml. I currently have:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; lock (<span style="color:Blue; this)
{
<span style="color:Green; // Load or Save...
}
[/code]
But this wont be reliable because even though the class is a Singleton since its getting accessed by multiple executables there will still be multiple instances of the class. Ive been able to do something similar with text files using FileStream
with the access and share parameters, but not sure how to apply this to working with an xml document (ideally Id like to continue using XElement, because changing it to something like XmlDocument would involve an overhaul of the way I have the class designed).
Any help would be appreciated.
Thanks,
-Dave
View the full article