// Downloads a file, see callbacks: DownloadCompleteCallback,DownloadProgressCallback private void DownloadFile(string url) { try { this.labProgressBytes.Text = "Requesting.."; this.progressBar.Minimum = 0; this.progressBar.Maximum = 0; this.progressBar.Value = 0; DownloadThread dl = new DownloadThread(); dl.DownloadUrl = url; dl.CompleteCallback += new DownloadCompleteHandler(DownloadCompleteCallback); dl.ProgressCallback += new DownloadProgressHandler(DownloadProgressCallback); dl.ErrorCallback += new DownloadErrorHandler(DownloadErrorCallback); this.dt = new Thread(new ThreadStart(dl.Download)); dt.IsBackground = true; dt.Name = "MP3Loader"; dt.Start(); while (dt.IsAlive) { Application.DoEvents(); if (this.cancelCalled) { break; } } } catch (WebException e) { this.labProgressBytes.Text = "Error: " + e.ToString(); } catch (Exception e) { this.labProgressBytes.Text = "Error: " + e.ToString(); } }