title: C# Form freeze when processing information
body: <p>I wrote a personal web scraper for myself that scraps artist information. the code works but when I press the button and it start processing the while loop, the GUI freezes. I got the textBoxes to .refresh(). But I can't move the form, also the only way to cancel the program is to force quit. I'm in the process of rewriting this so I don't get this problem. also, I heard about treading and wanted to see if that would work, and also make it a little faster. the program is scraping 15,000+ pages, and then each page has another 10 or so pages it needs to scrape. So, the program could run for hours before it's finally finished.</p>
  <p>Here is my code.</p>
  <pre><code>        private void btnGet_Click(object sender, EventArgs e)
      {
          int i = 0;
          int maxCount = 15000; //11234 was last value 
  
          progressBar.Maximum = maxCount;
  
          while (i &lt;= maxCount)
          {
              txbURL.Text = &quot;http://www.newreleasetuesday.com/albumdetail.php?album_id=&quot; + i;
              label.Text = i.ToString() + &quot; out of &quot; + maxCount.ToString() + &quot; Done.&quot;;
              progressBar.Value = i;
  
              string url = txbURL.Text;
  
              string sourceCode = sourceCode = WorkerClass.getSourceCode(url);
              int startIndex = sourceCode.IndexOf(&quot;//alert(document.getElementById(\&quot;remcheck\&quot;).value)&quot;);
              sourceCode = sourceCode.Substring(startIndex, sourceCode.Length - startIndex);
  
              //Start Artist Name
              //Gets the Artist's ID
              int idCountIndex = sourceCode.IndexOf(&quot;  by &lt;a href=\&quot;artistdetail.php?artist_id=&quot;) + 41;
              int idCountEndIndex = sourceCode.IndexOf(&quot;\&quot;&gt;&quot;, idCountIndex);
              string artistID = sourceCode.Substring(idCountIndex, idCountEndIndex - idCountIndex) + &quot;&quot;;
              txbArtistID.Text = artistID;
  
              //Gets Artist's Name
              startIndex = sourceCode.IndexOf(&quot;  by &lt;a href=\&quot;artistdetail.php?artist_id=&quot;) + 43 + artistID.Length;
              int endIndex = sourceCode.IndexOf(&quot;&lt;/a&gt; | Genre&quot;, startIndex);
              string artistName = sourceCode.Substring(startIndex, endIndex - startIndex) + &quot;&quot;;
              txbArtist.Text = artistName;
              //End Artist Name
  
              //Start Album Name
              //Gets Album's ID
              string albumID = url.Substring(url.IndexOf(&quot;=&quot;) + 1);
              txbAlbumID.Text = albumID;
  
              //Gets Album's Name
              startIndex = sourceCode.IndexOf(&quot;absbottom\&quot;&gt;&lt;/span&gt;&lt;/strong&gt; &quot;) + 28;
              endIndex = sourceCode.IndexOf(&quot;&lt;/span&gt;&lt;/td&gt;&quot;, startIndex);
              string AlbumName = sourceCode.Substring(startIndex, endIndex - startIndex) + &quot;&quot;;
              txbAlbum.Text = AlbumName;
              //End Album Name
  
              //Start Genre
              startIndex = sourceCode.IndexOf(&quot;&lt;/a&gt; | Genre: &quot;) + 14;
              endIndex = sourceCode.IndexOf(&quot; | &quot;, startIndex);
              string genre = sourceCode.Substring(startIndex, endIndex - startIndex) + &quot;&quot;;
              txbGenre.Text = genre;
              //End Genre
  
              //Start Release Date
              startIndex = sourceCode.IndexOf(&quot;&lt;a href=\&quot;releasedate.php?release_date=&quot;) + 50;
              endIndex = sourceCode.IndexOf(&quot; &lt;/a&gt;&lt;/td&gt;&quot;, startIndex);
              string releaseDate = sourceCode.Substring(startIndex, endIndex - startIndex) + &quot;&quot;;
              txbReleaseDate.Text = releaseDate;
              //End Release Date
  
              //Start Pic URL
              startIndex = sourceCode.IndexOf(&quot;&lt;img  src=\&quot;&quot;) + 11;
              endIndex = sourceCode.IndexOf(&quot;\&quot;  alt=&quot;, startIndex);
              string PicURL = sourceCode.Substring(startIndex, endIndex - startIndex) + &quot;&quot;;
              PicURL = PicURL.Replace(&quot;amp;&quot;, &quot;&quot;);
              string fullLink = &quot;http://www.newreleasetuesday.com/&quot; + PicURL;
              txbPicURL.Text = fullLink;
              //End Pic URL
  
  
              //Refresh UI (Updates textBoxes, labels, and progressBar with new values)
              txbURL.Refresh();
              txbArtist.Refresh();
              txbAlbum.Refresh();
              txbReleaseDate.Refresh();
              txbGenre.Refresh();
              txbPicURL.Refresh();
              txbArtistID.Refresh();
              txbAlbumID.Refresh();
              label.Refresh();
              progressBar.Refresh();
  
              if (artistName == &quot;&quot;)
              {
                  // Adding info to Database if there is no artist name
                  string cs = &quot;SERVER=asdf.net;&quot; +
                      &quot;DATABASE=music;&quot; +
                      &quot;UID=root;&quot; +
                      &quot;PASSWORD=asdf;&quot;;
  
                  MySqlConnection conn = null;
  
                  conn = new MySqlConnection(cs);
                  conn.Open();
  
                  MySqlCommand cmd = new MySqlCommand();
                  cmd.Connection = conn;
                  cmd.CommandText = &quot;INSERT INTO `emptyalbums` (id, albumid) VALUES('',@albumid)&quot;;
                  cmd.Prepare();
  
                  cmd.Parameters.AddWithValue(&quot;@albumid&quot;, albumID);
  
                  cmd.ExecuteNonQuery();
                  conn.Close();
              }
              else
              {
                  // Adding info to Database if there is an artist name
                  string cs = &quot;SERVER=asdf.net;&quot; +
                      &quot;DATABASE=music;&quot; +
                      &quot;UID=root;&quot; +
                      &quot;PASSWORD=asdf;&quot;;
  
                  MySqlConnection conn = null;
  
                  conn = new MySqlConnection(cs);
                  conn.Open();
  
                  MySqlCommand cmd = new MySqlCommand();
                  cmd.Connection = conn;
                  cmd.CommandText = &quot;INSERT INTO `database` (id, artist, album, releasedate, genre, pictureurl, artistid, albumid) VALUES('',@artist, @album, @releasedate, @genre, @pictureurl, @artistid, @albumid)&quot;;
                  cmd.Prepare();
  
                  cmd.Parameters.AddWithValue(&quot;@artist&quot;, artistName);
                  cmd.Parameters.AddWithValue(&quot;@album&quot;, AlbumName);
                  cmd.Parameters.AddWithValue(&quot;@releasedate&quot;, releaseDate);
                  cmd.Parameters.AddWithValue(&quot;@genre&quot;, genre);
                  cmd.Parameters.AddWithValue(&quot;@pictureurl&quot;, fullLink);
                  cmd.Parameters.AddWithValue(&quot;@artistid&quot;, artistID);
                  cmd.Parameters.AddWithValue(&quot;@albumid&quot;, albumID);
  
                  cmd.ExecuteNonQuery();
                  conn.Close();
              }
              i++;
              
          }
  </code></pre>
  <p>Any info would go a long way.
  Thanks,
  Throdne</p>