title: How to wait for a file to be saved before executing next line of code?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2678079/is-xmldocument-save-an-atomic-operation">Is XMLDocument.Save an atomic operation?</a>  </p>
  </blockquote>
  
  
  
  <p>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.</p>
  
  <p>I could use <code>Thread.Sleep</code> but on slower computers it might still crash if it took too long.</p>
  
  <p>I'm using <code>XmlDocument.Save</code> 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.</p>