title: Read FileStream with timeout
body: <p>I wrote this code to read some data from a FileStream with a timeout:</p>
  <pre class="lang-cs prettyprint-override"><code>private CancellationTokenSource RCTS = new CancellationTokenSource();
  
  private int ReadTimeOut = 500;
  
  //...
  
  private byte[] ReadData()   //Blocking Method (until operation done or timeout)
  {
      byte[] Buffer = new byte[ReadSize];
      Task&lt;int&gt; ReadTask = FStream.ReadAsync(Buffer, 0, ReadSize, RCTS.Token);    //Problem
      if (ReadTask.Wait(ReadTimeOut))
      {
          if (ReadTask.Status == TaskStatus.Canceled) RCTS = new CancellationTokenSource();   //Cancelled manually
          return Buffer;
      }
      RCTS.Cancel();
      RCTS = new CancellationTokenSource();
      throw new TimeoutException(&quot;Read operation timed out.&quot;);
  }
  </code></pre>
  <p>However, code stops on <code>//Problem</code> line until read operation is done (enough data available). So timeout is useless.<br />
  <code>FStream.CanTimeout</code> is false and I can't use <code>FStream.ReadTimeout</code>. <code>FStream</code> is async.</p>
  <p>Why it stops there? Shouldn't it just assign <code>ReadTask</code> and then run it on <code>ReadTask.Wait(ReadTimeOut)</code>?</p>