Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd node in XML file crashes
    primarykey
    data
    text
    <p>I created a ping application with a service that pings to URLs. The list of the URLs is stored in an XML file.<br> My application crashes when I'm trying to add a new site to my XML while the service is running. </p> <p>VS2010 says my file is being used by some other process but I'm sure that everything is fine. My service isn't using the XML while I'm adding to it.</p> <p>BUT I guess using an XmlReader &amp; XmlWriter at the same time is where it crashes.<br> I'll rewrite my code with LINQ to XML but I was wondering if it's possible to use XmlReader &amp; XmlWriter at the same time?</p> <pre><code>private void saveSites(Site newSite) { XmlDocument XDoc = new XmlDocument(); bool fileExists = true; if (File.Exists("c:\\temp\\sites.xml") == false) { createXML(); fileExists = false; } using (XmlReader XReader = XmlReader.Create("c:\\temp\\sites.xml")) { XDoc.Load(XReader); if (fileExists == true) { XmlNode SiteNode = XDoc.CreateNode(XmlNodeType.Element, "site", ""); XmlNode URLNode = XDoc.CreateNode(XmlNodeType.Element, "url", ""); URLNode.InnerText = newSite.URL; XmlNode EmailNode = XDoc.CreateNode(XmlNodeType.Element, "email", ""); EmailNode.InnerText = newSite.Email; SiteNode.AppendChild(URLNode); SiteNode.AppendChild(EmailNode); XDoc.DocumentElement.AppendChild(SiteNode); } else { foreach (Site site in sites) { XmlNode SiteNode = XDoc.CreateNode(XmlNodeType.Element, "site", ""); XmlNode URLNode = XDoc.CreateNode(XmlNodeType.Element, "url", ""); URLNode.InnerText= site.URL; XmlNode EmailNode = XDoc.CreateNode(XmlNodeType.Element, "email", ""); EmailNode.InnerText = site.Email; SiteNode.AppendChild(URLNode); SiteNode.AppendChild(EmailNode); XDoc.DocumentElement.AppendChild(SiteNode); } } XDoc.Save("c:\\temp\\sites.xml"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload