My web site writes to XML files.
This is an example of the write to: a task xml .
/// <summary>
/// The name of the xml file containing the tasks data.
/// </summary>
private string tasksFile;
/// <summary>
/// The Xml Document that stores the contents of the tasks
/// xml file in memory once loaded.
/// </summary>
private XDocument tasksXml;
........
/// <summary>
/// Writes the xml task file to the disk
/// </summary>
private void SaveTask()
{
this.tasksXml.Save(this.tasksFile);
}
The tasksXml XDocument is loaded, then processed and only then saved using the Save method.
As more than one user can try to write to the file at the same time, user A might override changes performed by user B.
Edit:
Trying to avoid User A opens, user B opens, both edit, then both save their changes (so only one wins)
-
A. How do I ensure that multiple
users do not overwrite each other’s
work? -
B. Would the term singleton be
correct – if so how is it
implemented?
The only option that I have found that is inline with how I think it should be done is explained in the following link on SO. It uses a temporary file to indicate whether the XML file is “locked”.