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());
}
}
}
}
}
}
}