title: How can I read a file even when getting an "in use by another process" exception?
body: <p>In VB.NET or C#, I'm trying to read the contents of a text file that is in use by another program (that's the point, actually, I can't stop the program or it stops writing to the text file, and I want to periodically read out what is currently in the text file in another program).</p>
  
  <p>This is the code I'm using (VB.NET)</p>
  
  <pre><code>Dim strContents As String
  Dim objReader As StreamReader
  objReader = New StreamReader(FullPath)
  strContents = objReader.ReadToEnd()
  objReader.Close()
  </code></pre>
  
  <p>Or in C#:</p>
  
  <pre><code>var objReader = new StreamReader(FullPath);
  var strContents = objReader.ReadToEnd();
  objReader.Close();
  </code></pre>
  
  <p>The above, however, throws the IO exception "The process cannot access the file 'file.txt' because it is being used by another process." Are there any workarounds in this scenario?</p>