title: New FileStream already closed/disposed?
body: <p>I open a <code>FileStream</code> with <code>FileMode.Open</code> and <code>FileAccess.Read</code>. Shortly after that I call a function to handle the file's contents. I use <code>Invoke</code> to make the call because the call comes from a <code>Thread</code> and the function has to put the results on a <code>Form</code>. The function accepts any kind of Stream (I call it with <code>MemoryStream</code>s too without a problem) and uses <code>XmlTextReader</code> to read the XML in the <code>FileStream</code>, but on rare occasions for unknown reasons even the first <code>Read()</code> throws an <code>ObjectDisposedException</code> and the stream's <code>CanRead</code> property returns false if the stream was already closed.</p>
  
  <p>In the <code>Thread</code> the <code>FileStream</code> is a local <code>using</code> variable, so I don't think another threads should be able to close it, and I don't close it until the <code>Invoke</code> returned. There are no <code>Exceptions</code> thrown so the file is definetly there (since there is no <code>FileNotFoundException</code>) and should be accessed properly (since there is no <code>UnauthorizedAccessException</code> and <code>IOException</code>).</p>
  
  <p>How could my <code>FileStream</code> still look closed sometimes just after opened?</p>
  
  <p>(It might matter that I'm running my code on a Windows CE 5 device with Compact Framework 3.5 and I wasn't able to reproduce the same behaviour on my desktop PC with XP yet.)</p>
  
  <p><strong>EDIT:</strong>
  I know, that this Invoke is ugly but that alone can't be a reason to fail, can it? (And, in most of the cases it doesn't fail at all.)</p>
  
  <pre><code>//the code in the thread
  //...
  using (FileStream fs = File.Open(assemblyPath + "\\white.xml", FileMode.Open, FileAccess.Read))
  {
      mainForm.Instance.Invoke(new DataHandler(mainForm.Instance.handleData), new object[] { fs });
  }
  //...
  
  //and the handler
  public void handleData(Stream stream)
  {
      infoPanel.SuspendLayout();
      try
      {
          using (XmlTextReader xml = new XmlTextReader(stream))
          {
              //it doesn't matter what is here
          }
      }
      catch{}
  }
  </code></pre>