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

The Archive Base Latest Questions

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

I have a timer that loops through following code every second. this code reads

  • 0

I have a timer that loops through following code every second. this code reads a few xml fragments one after another then prints them to the screen, it then repeats this a second later. output:

34,
23,
12,

What I want to do is to make write all the data to a string like 34,23,12 then returns it so that another class can use it. But if I put it(the string code , you’ll see it below) under the if (fragmentReader.Read()) code it doesn’t work as it just does the same thing as the console.writeline above it: reads one of the fragments then writes to console, then the next fragment, it doesn’t add all the values from the fragment into one string.

thanks

private static void OnTimedEvent(object source, ElapsedEventArgs e)
    {
        using (var file = MemoryMappedFile.OpenExisting("AIDA64_SensorValues"))
        {
            using (var readerz = file.CreateViewAccessor(0, 0))
            {
                var bytes = new byte[195];
                var encoding = Encoding.ASCII;
                readerz.ReadArray<byte>(0, bytes, 0, bytes.Length);

                //File.WriteAllText("C:\\myFile.txt", encoding.GetString(bytes));

                StringReader stringz = new StringReader(encoding.GetString(bytes));

                var readerSettings = new XmlReaderSettings { ConformanceLevel = ConformanceLevel.Fragment };
                using (var reader = XmlReader.Create(stringz, readerSettings))
                {
                    while (reader.Read())
                    {
                        using (var fragmentReader = reader.ReadSubtree())
                        {
                            if (fragmentReader.Read())
                            {
                                reader.ReadToFollowing("value");
                                //Console.WriteLine(reader.ReadElementContentAsString() + ",");

                                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                                sb.Append(reader.ReadElementContentAsString()).Append(",");
                                Console.WriteLine(sb.ToString());
                            }
                        }
                    }
                }                
            }
        }
    }
  • 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-25T11:08:53+00:00Added an answer on May 25, 2026 at 11:08 am

    The problem is that in every iteration of the loop you are creating a new stringbuilder object. You need to create that object before your loop, then print the string after the loop.

    What you want:

                     System.Text.StringBuilder sb = new System.Text.StringBuilder();
                     while (reader.Read())
                        {
                            using (var fragmentReader = reader.ReadSubtree())
                            {
                                if (fragmentReader.Read())
                                {
                                    reader.ReadToFollowing("value");
                                    //Console.WriteLine(reader.ReadElementContentAsString() + ",");
    
    
                                    sb.Append(reader.ReadElementContentAsString()).Append(",");
                                }
                            }
                        }
                        Console.WriteLine(sb.ToString());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that will be accessed from two threads: class Timer{ public:
I have some code that does the following: while(some condition) { char *line[WORDLEN]; //do
If I have an instance of a System.Timers.Timer that has a long interval -
I have a control that is basically functioning as a client-side timer countdown control.
I have quite straight forward question. The following code prints out celsius and fahrenheit.
I have a script that appends some rows to a table. One of the
I have a php script that steps through a folder containing tab delimited files,
The problem I am trying to avoid code that looks like the following: If(object
I have the following code which does what it's supposed to do: objSQLCommand =
I have the following code, which I am using to test how I'm using

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.