title: How to check if a file is in use?
body: <p>Is there any way to first test if a file is in use before attempting to open it for reading?  For example, this block of code will throw an exception if the file is still being written to or is considered in use:</p>
  
  <pre><code>try
  {
      FileStream stream = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  }
  catch (IOException ex)
  {
      // ex.Message == "The process cannot access the file 'XYZ' because it is being used by another process."
  }
  </code></pre>
  
  <p>I've looked all around and the best I can find is to perform some sort of polling with a try catch inside, and that feels <em>so</em> hacky.  I would expect there to be something on <code>System.IO.FileInfo</code> but there isn't.</p>
  
  <p>Any ideas on a better way?</p>