title: Web Request Get Response fails on second try
body: <p>I wrote a program that searches for a user name on a web site and downloads the their main html page, finds the link to the next page and downloads that and so on. When I run the program the first time the get response for the search works correctly and the get response for downloading all of html pages works correctly. However, when I do a second search the get response fails for the search. I thought that maybe it was the server only allowing so many searches in a time period but it isn't that. When I close my program and run it again everything works fine again. Why does the get response fail on any attempts besides the initial one? You can't define a web request as new and their seems to be no way of closing a web request once it gets a response to free up resources. Is it because I run the whole process in a background worker? I don't know what's wrong. I always could do as many searches as I wanted to just yesterday...</p>
  
  <p>Here's my code for the search form:</p>
  
  <pre><code>Private Sub FormSearch_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      'if the user name is empty then initialize it
      If My.Settings.UserName = "" Then
          My.Settings.UserName = ""
      End If
      'if the current url is empty then initialize it
      If My.Settings.CurrentURL = "" Then
          My.Settings.CurrentURL = ""
      End If
      My.Settings.Save()
  End Sub
  
  Private Sub TextBoxUserName_TextChanged(sender As Object, e As EventArgs) Handles TextBoxUserName.TextChanged
      'if the text length of the text box is greater then zero
      If TextBoxUserName.TextLength &gt; 0 Then
          'enable the search button
          ButtonSearch.Enabled = True
      Else
          'disable the search button and set focus on the text box
          ButtonSearch.Enabled = False
          TextBoxUserName.Focus()
      End If
  End Sub
  
  Private Sub ButtonSearch_Click(sender As Object, e As EventArgs) Handles ButtonSearch.Click
      'trim the text box of any spaces
      My.Settings.UserName = Trim(TextBoxUserName.Text)
      'if the user name is not equal to null
      If My.Settings.UserName &lt;&gt; "" Then
          'set the current url and test if it exists
          My.Settings.CurrentURL = "*url here*"
          If URLExists(My.Settings.CurrentURL) = True Then
              'save the settings
              My.Settings.Save()
              'return ok for the dialog result and close the form
              Me.DialogResult = Windows.Forms.DialogResult.OK
              Me.Close()
          Else 'cannot find the account
              'set the text box text to null and set focus on it
              TextBoxUserName.Text = ""
              TextBoxUserName.Focus()
          End If
      End If
  End Sub
  
  Private Function URLExists(url As String) As Boolean
      'create a new uri
      Dim uriURL As New Uri(url)
      'create a new web request of the uri
      Dim wrRequest As WebRequest = WebRequest.Create(uriURL)
      'set the web request timeout and method
      wrRequest.Timeout = 30000
      wrRequest.Method = "GET"
      'create a new web response
      Dim wrResponse As WebResponse
      Try
          'if the response succeeds then return true
          wrResponse = wrRequest.GetResponse
          Return True
      Catch ex As Exception 'the response failed so return false
          LabelMessage.Text = ex.Message
          Return False
      End Try
  End Function
  </code></pre>