I know that when calling asynchronous methods a Thread is allocated from the pool and this has a cost.
XmlReader has asynchronous implementations:
using (var r = XmlReader.Create(fs, new XmlReaderSettings() { Async = true }))
{
while (await r.ReadAsync())
{
if (r.IsStartElement())
{
switch (r.Name)
{
case "a": var a = await r.ReadElementContentAsStringAsync(); break;
case "b": var b = await r.ReadElementContentAsStringAsync(); break;
case "c": var c = await r.ReadElementContentAsStringAsync(); break;
}
}
}
}
Wouldn't it be a waste of processing to allocate threads in the pool to perform a process as simple as reading an xml element?
I imagine that asynchronous reads in xml should be used only when the content of the tag is known to be large, such as strings in base64, etc.
The code above written synchronously, wouldn't be more performance? Of course, reading about 5,000 xml files or a single large xml file.