title: Killing HttpWebRequest object using Thread.Abort
body: <p>All, I am trying to cancel two concurrent HttpWebRequests using a method similar to the code below (shown in pseudo-ish C#).</p>
  
  <p>The Main method creates two threads which create HttpWebRequests.  If the user wishes to, they may abort the requests by clicking a button which then calls the Abort method.</p>
  
  <pre><code>private Thread first;
  private Thread second;
  private string uri = "http://somewhere";
  
  public void Main()
  {
    first = new Thread(GetFirst);
    first.Start();
  
    second = new Thread(GetSecond);
    second.Start();
  
    // Some block on threads... like the Countdown class
    countdown.Wait();
  }
  
  public void Abort()
  {
    try
    {
      first.Abort();
    }
    catch { // do nothing }
  
    try
    {
      second.Abort();
    }
    catch { // do nothing }
  }
  
  private void GetFirst(object state)
  {
    MyHandler h = new MyHandler(uri);
    h.RunRequest();
  }
  
  private void GetSecond(object state)
  {
    MyHandler h = new MyHandler(uri);
    h.RunRequest();
  }
  </code></pre>
  
  <p>The first thread gets interrupted by a SocketException:</p>
  
  <pre><code>A blocking operation was interrupted by a call to WSACancelBlockingCall
  </code></pre>
  
  <p>The second thread hangs on GetResponse().</p>
  
  <p><strong>How can I abort both of these requests in a way that the web server knows that the connection has been aborted?</strong>, and/or, <strong>Is there a better way to do this?</strong></p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>As suggested, a good alternative would be to use BeginGetResponse.  However, I don't have access to the HttpWebRequest object - it is abstracted in the <code>MyHandler</code> class.  I have modified the question to show this.</p>
  
  <pre><code>public class MyHandler
  {
    public void RunRequest(string uri)
    {
      HttpWebRequest req = HttpWebRequest.Create(uri);
      HttpWebResponse res = req.GetResponse();
    }
  }
  </code></pre>