title: How to cancel reading from a Stream obtained using HttpWebResponse.GetResponseStream()?
body: <p>I use HttpWebResponse.BeginGetResponse() method to make a request to my server. In the "Request Complete" notification I do the following (no error handling code included):</p>
  
  <pre><code>HttpWebResponse response = (HttpWebResponse)myHttpWebRequest.EndGetResponse(result);
  BinaryReader streamReader = new BinaryReader(response.GetResponseStream());
  
  while ((readSize = streamReader.Read(buffer, 0, buffer.Length)) &gt; 0)
  {
  ...
  }
  </code></pre>
  
  <p>My question is if it is OK to store the Stream obtained from response.GetResponseStream()  somewhere as a member variable and make the Cancel of the request like this:</p>
  
  <pre><code>m_requestState.httpRequest.Abort();
  m_requestState.httpRequestStream.Close(); // If this is missing then
  // streamReader.Read() locks for a long time when connection is lost.
  </code></pre>
  
  <p>This code causes the streamReader.Read() to throw System.ObjectDisposedException.</p>
  
  <p>Thank you!<br/>
  Mihai</p>