I have written two applications and one starts the other one using
Process.Start(path_to_app2);
App2 starts as expected.
Both of the applications save own xml configs files.
and sometimes one xml ( that is first written by app 1 ) is overwritten by app 2
even if it is running in separate catalog.
this overwriting does not happen when app 2 is started alone from inside its own folder
when I run Save routine both of them have the same content in app1 and app2
I use the same conf.xml file name by assumption that both apps are in different forlders.
public void Save(string fileName)
{
string path = Environment.CurrentDirectory + "\" + fileName;
//first serialize the object to memory stream,
//in case of exception, the original file is not corrupted
using (MemoryStream ms = new MemoryStream())
{
var writer = new System.IO.StreamWriter(ms);
var serializer = new XmlSerializer(this.GetType());
serializer.Serialize(writer, this);
writer.Flush();
//if the serialization succeed, rewrite the file.
File.WriteAllBytes(path, ms.ToArray());
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…