title: How can I prevent UI freezing while using HttpWebRequest?
body: <p>I have a progressBar on my form and a button. 
  When user clicks this button, the progressBar should be styled as "marquee" and the program begins to check is an URL is valid or not.. OK.</p>
  
  <p>But when I click the button, the UI freezes until the HttpStatusCode returns true or false...</p>
  
  <p>Here is the check code:</p>
  
  <pre><code>private bool RemoteFileExists(string url)
  {
     try
     {
        HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
        request.Method = "HEAD";
        HttpWebResponse response = request.GetResponse() as HttpWebResponse;
        return (response.StatusCode == HttpStatusCode.OK);
     }
     catch
     {
        return false;
     }
  }
  </code></pre>
  
  <p>And here is the button click code:</p>
  
  <pre><code>private async void button1_Click(object sender, EventArgs e)
  {
     this.progressBar1.Style = System.Windows.Forms.ProgressBarStyle.Marquee;
     var result = RemoteFileExists("http://www.google.com/");
     if (Completed)
     {
        //ok
     }
     else
     {
        //not ok
     }
  }
  </code></pre>