title: While Loop Locks UI Thread
body: <p>I have a button in my WinForms application with the following Click event:</p>
  
  <pre><code>    private void Button_Click(object sender, EventArgs e)
      {
          treasureFound = false;
          refreshNumber = 0;
  
          Label_StartDateTime.Text = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");
          while (!treasureFound)
          {
              Label_StatusData.Text = "Refreshed " + refreshNumber + " times.";
              refreshNumber++;
              using (WebClient client = new WebClient())
              {
                  string htmlCode = client.DownloadString(webUrl);
  
                  if (htmlCode.Contains("Treasure"))
                  {
                      treasureFound = true;
                      Label_StatusData.Text = "Found.";
                      // etc etc
                  }
              }
          }
      }
  </code></pre>
  
  <p>When the button is clicked, the UI thread locks up (not responding, labels don't update) until the while loop ends.</p>
  
  <p>What can I do to keep the UI responsive? There should only be one WebClient instance at any one time.</p>