title: Check if a file is in use, wait for it to finish
body: <p>I have this problem in my application:</p>
  
  <ul>
  <li>Step 1 - create an file (xml) and put some content in it  </li>
  <li>Step 2 - a 3rd party application will open the file and get the info from the file made in step 1.  </li>
  <li>Step 3 - delete the file again.  </li>
  </ul>
  
  <p>The first question that I have is about this part of the code:</p>
  
  <pre><code>XmlDocument xmlDoc = new XmlDocument();
  DataSet ds = //use a method to put in the data
  xmlDoc.LoadXml(ds.GetXml());
  xmlDoc.Save("Filename");
  // ...
  Process.Start(startInfo);
  </code></pre>
  
  <p>Is my assumption correct that the last line only gets executed when the above is already done?
  So I can be 100% sure that the data is all in the xml before it tries to start it right?</p>
  
  <p>The second part where I get an error now is here:</p>
  
  <pre><code>Process.Start(startInfo);
  File.Delete("Filename");
  </code></pre>
  
  <p>What happens now, is that the file already gets deleted before the 3rd party program had read it into its memory.</p>
  
  <p>Is there some way that I can check that the file is no longer in use, or make some stable way of waiting?</p>
  
  <p>I already found a way to use <code>Thread.Sleep(TimeInMiliSec);</code> but I guess this is not a correct way of doing this (more like a workaround solution)?</p>