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 9278525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:23:50+00:00 2026-06-18T17:23:50+00:00

I have made a service which reads an xml. In the xml i have

  • 0

I have made a service which reads an xml. In the xml i have Input directory and output directory. The service picks the files in the input directory and renames them and moves them to the output directory. I want to implement threading in the service. I want it to pick one node of xml in one thread and other in the other. Or it would even be good if irrespective of nodes one thread picks the first 10 operations to be performed and the next the next 10 and so on. So that all the nodes are processed in a parallel fashion. Can anyone help me on this? i tried reading through a few threading tutorials but could not gain much through them. The service code is as follows:

XmlDocument doc = new XmlDocument();
            doc.Load("Data.xml");
            int count = doc.SelectNodes("Data/DataClass").Count;
            for (int i = 1; i < count; i++)
            {
                string xpath = "/Data/DataClass[" + i + "]";
                XmlNode node = doc.SelectSingleNode(xpath);
                XmlNodeList subnode = node.ChildNodes;
                string pathO = "";
                string pathI = subnode[0].InnerText;
                string prefix = subnode[2].InnerText;
                string freq = subnode[3].InnerText;
                string[] filenames = Directory.GetFiles(pathI);
                node.ParentNode.RemoveChild(doc.SelectSingleNode(xpath));
                doc.Save("Data.xml");

                foreach (string filename in filenames)
                {
                    pathO = subnode[1].InnerText;
                    pathO = pathO + "\\" + prefix;
                    string fname = Path.GetFileName(filename);
                    pathO = pathO + fname;
                    System.IO.File.Move(filename, pathO);

                }
            } 
  • 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-06-18T17:23:51+00:00Added an answer on June 18, 2026 at 5:23 pm

    Use Parallel.For or Parallel.ForEach, check the following code, its simple , i’ve modified your code here only so check it with VS (there maybe small changes as per your requirement).

    XmlDocument doc = new XmlDocument();
    doc.Load("Data.xml");
    int count = doc.SelectNodes("Data/DataClass").Count;
    Parallel.For(0,doc.SelectNodes("Data/DataClass").Count-1,i =>
    {
        XmlNode node = doc.SelectNodes("Data/DataClass")[i];
        XmlNodeList subnode = node.ChildNodes;
        string pathO = "";
        string pathI = subnode[0].InnerText;
        string prefix = subnode[2].InnerText;
        string freq = subnode[3].InnerText;
        string[] filenames = Directory.GetFiles(pathI);
        doc.Save("Data.xml");
        foreach (var filename in filenames)
        {
            pathO = subnode[1].InnerText;
            pathO = pathO + "\\" + prefix;
            string fname = Path.GetFileName(filename);
            pathO = pathO + fname;
            System.IO.File.Move(filename, pathO);
        }
    }
    );
    

    Don’t remove the child node inside Parallel loop so i removed the following line
    node.ParentNode.RemoveChild(node);

    Learn more about Task Parallel Liberary (http://msdn.microsoft.com/en-us/library/dd537608.aspx) for parallel processing features given.

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

Sidebar

Related Questions

I have been made a windows service.in which i have been added project installer.in
I made a Web service in which I have a function to count some
I have made a Windows Service that gets installed in a c:\Program Files\My Service
I have made a small log service that i want to publish to a
I have just made a portlet with web service for liferay to learn how
I have wrote a Windows Service and I have a admin panel which I
I have a aplication in which i read the xml file that are stored
I have an activity which I want to use to display data sent from
I have made a jQuery toggle for a menu that I had in mind.
I have made an application for IPad in objective C. In this I am

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.