Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6742661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:52:12+00:00 2026-05-26T11:52:12+00:00

I created a ping application with a service that pings to URLs. The list

  • 0

I created a ping application with a service that pings to URLs. The list of the URLs is stored in an XML file.
My application crashes when I’m trying to add a new site to my XML while the service is running.

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.

BUT I guess using an XmlReader & XmlWriter at the same time is where it crashes.
I’ll rewrite my code with LINQ to XML but I was wondering if it’s possible to use XmlReader & XmlWriter at the same time?

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");
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:52:12+00:00Added an answer on May 26, 2026 at 11:52 am

    Your reader is blocking the writing because it is in the using block. I’d suggest using the Load method the XmlDocument object with a uri instead of creating your own reader. Then also you can separate the initilisation from the writing operation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that populates list views when a view is created. I
I'm trying to make a simple app that will ping a uri and tell
Created .NET WCF service, tested it - works. Generated schemas from Data and service
Created an OpenGraph action and object. Trying to submit my action. When I click
I created a batch file to run SqlMetal and generate Linq2Sql data classes, check
I created a proxy of a Web Service with Visual Studio 2008, and it
I created a project in flex builder with application server type set to none.
I created a JApplet using Netbeans 6.5.1 that accesses a database. When the program
I am trying to have a parallel functionality in my asp.net mvc 2 application.
I have 2 questions for you. Im creating an Application for Chat that relies

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.