Possible Duplicate:
Is XMLDocument.Save an atomic operation?
I appear to have a Heisenbug in my program. I need to export an Xml file and then re-import it. The problem is that sometimes before the Xml file has finished saving the program will continue to the next line to try and re-import it and because it is not finished saving the application will crash. When I debug it there is enough time for the file to save so the program doesn’t crash.
I could use Thread.Sleep but on slower computers it might still crash if it took too long.
I’m using XmlDocument.Save to save the file. I was wondering if there might be a way to implement a callback of some sort for when the file has been completely saved.
Suspect antivirus. Many virus scanners aren’t written well and lock the file when you close it, preventing any program from opening it for a few seconds.
See this question: