Astartechie
Astartechie
CC#
Created by Astartechie on 2/17/2024 in #help
Issue with XmlReader
I am having an issue with XmlReader skipping the contents of a file. If I uncomment the Thread.Sleep, it works perfectly fine. Am I doing something wrong or should this work?
public void Import()
{
_logger.LogInformation("Beginning Import.");
var fs = new FileStream(@"test.xml", FileMode.OpenOrCreate,
FileAccess.Read, FileShare.Read);

using var reader = XmlReader.Create(fs);
while (!reader.EOF)
{
if (reader.Read())
{
_logger.LogInformation($"Type: {reader.NodeType}, Name: {reader.Name}, Value: {reader.Value}");
}
else
{
_logger.LogError("COULDNT READ");
}
}
//Thread.Sleep(1000); //Only Works when sleeping
}
public void Import()
{
_logger.LogInformation("Beginning Import.");
var fs = new FileStream(@"test.xml", FileMode.OpenOrCreate,
FileAccess.Read, FileShare.Read);

using var reader = XmlReader.Create(fs);
while (!reader.EOF)
{
if (reader.Read())
{
_logger.LogInformation($"Type: {reader.NodeType}, Name: {reader.Name}, Value: {reader.Value}");
}
else
{
_logger.LogError("COULDNT READ");
}
}
//Thread.Sleep(1000); //Only Works when sleeping
}
26 replies