Working with IOExceptions using XmlWriter.Create () and XmlDocument.Load () in separate threads

I inherited some code that includes a scheduled task that writes data (received from an external source) into XML files and a website that reads the specified XML files to get information for the visitor.

There is no synchronization, and, of course, sometimes the scheduling task cannot write a file because it is currently open for reading.

The heart of the write code is:

XmlWriter writer = XmlWriter.Create(fileName);
try
{
  xmldata.WriteTo(writer);
}
finally
{
  writer.Close();
}

And the heart of the reader code:

XmlDocument theDocument = new XmlDocument();
theDocument.Load(filename);

(exception handled at both ends)

, . , XmlWriter.Create(), XmlDocument.Load() . ( ) .Create() .Load(), Stream?

IOExceptions - ", , "?

+3
1

- XmlDocument, FileStream FileShare.ReadWrite. XmlWriter .

, xml FileStream MemoryStream . FileShare.ReadWrite, , .

FileShare.ReadWrite ( FileShare.Write, ) , , , . XML-, XmlDocument.Load. , " ". , , , , , , . ( ) , . .

, . , , . .NET, Mutex, ( -). Mutex .

+2

Source: https://habr.com/ru/post/1756484/


All Articles