Im trying to make a simple downloader, but i cant make it to update the GUI elements in my Form (Form1
).
In the constructor for Form1 i call thread:
Thread t = new Thread(new ThreadStart(fetch));
t.Start();
And fetch looks something like this:
private void fetch()
{
try
{
WebClient webClient = new WebClient();
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged);
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(webClient_DownloadFileCompleted);
webClient.DownloadFile(updateurl, @"foo.iso");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n\n" + ex.InnerException.ToString());
}
}
None of the events are triggered... altho, by looking at the foo.iso in the folder i see the file increase in size.
One of the events looks like this:
void webClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar.Value = (int)(e.BytesReceived * 100 / e.TotalBytesToReceive);
statusLabel.Text = "Downloading";
descLabel.Text = progressBar.Value + " % complete";
}