Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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());
            }
        }

question from:https://stackoverflow.com/questions/65601035/xml-file-corrupted-by-other-application

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
139 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...