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

  • Home
  • SEARCH
  • 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 7429833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:02:28+00:00 2026-05-29T09:02:28+00:00

I am developing a program to log data from a incoming serial communication. I

  • 0

I am developing a program to log data from a incoming serial communication. I have to invoke the serial box by sending a command, to recieve something. All this works fine, but i have a problem.

The program have to be run from a netbook ( approx: 1,5 gHZ, 2 gig ram ), and it can’t keep up when i ask it to save these information to a XML file.

I am only getting communication every 5 second, i am not reading the file anywhere.

I use xml.save(string filename) to save the file.

Is there another, better way, to save the information to my XML, or should i use an alternative?

If i should use an alternative, which should it be?

Edit:
Added some code:

            XmlDocument xml = new XmlDocument();
            xml.Load(logFile);

            XmlNode p = xml.GetElementsByTagName("records")[0];
            for (int i = 0; i < newDat.Length; i++)
            {
                XmlNode q = xml.CreateElement("record");

                XmlNode a = xml.CreateElement("time");
                XmlNode b = xml.CreateElement("temp");
                XmlNode c = xml.CreateElement("addr");

                a.AppendChild(xml.CreateTextNode(outDat[i, 0]));
                b.AppendChild(xml.CreateTextNode(outDat[i, 1]));
                c.AppendChild(xml.CreateTextNode(outDat[i, 2]));

                sendTime = outDat[i, 0];

                points.Add(outDat[i, 2], outDat[i, 1]);

                q.AppendChild(a);
                q.AppendChild(b);
                q.AppendChild(c);

                p.AppendChild(q);
            }

            xml.AppendChild(p);
            xml.Save(this.logFile);

This is the XML related code, running once every 5 seconds. I am reading (I get no error), adding some childs, and then saving it again. It is when I save that I get the error.

  • 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-29T09:02:28+00:00Added an answer on May 29, 2026 at 9:02 am

    You may want to look at using an XMLWriter and building the XML file by hand. That would allow you to open a file and keep it open for the duration of the logging, appending one XML fragment at a time, as you read in data. The XMLReader class is optimized for forward-only writing to an XMLStream.

    The above approach should be much faster when compared to using the Save method to serialize (save) a full XML document each time you read data and when you really only want to append a new fragment at the end.

    EDIT

    Based on the code sample you posted, it’s the Load and Save that’s causing the unnecessary performance bottleneck. Every time you’re adding a log entry you’re essentially loading the full XML document and behind the scenes parsing it into a full-blown XML tree. Then you modify the tree (by adding nodes) and then serialize it all to disk again. This is very very counter productive.

    My proposed solution is really the way to go: create and open the log file only once; then use an XMLWriter to write out the XML elements one by one, each time you read new data; this way you’re not holding the full contents of the XML log in memory and you’re only appending small chunks of data at the end of a file – which should be unnoticeable in terms of overhead; at the end, simply close the root XML tag, close the XMLWriter and close the file. That’s it! This is guaranteed to not slow down your UI even if you implement it synchronously, on the UI thread.

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

Sidebar

Related Questions

I am developing a C# program, and i have one function that consumes too
I am developing program which need to interact with COM ports. By learning from
I am developing program on window's using msys and mingw. I want to have
I'm currently developing a program that will generate reports based upon lead data. My
I am developing a program in VB.NET. I have an enum called PriceType that
I'm currently developing a program in python and I just noticed that something was
I have been developing a program lately that compiles and runs a C++ Program
I am developing a php MVC framework from scratch and have run into an
I am developing a program which sends images from one computer to another (similar
I'm developing a program that receives some data and after processing I want to

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.