0
td well? I am very new in programming, I took a project of a Auncher with autoupdate already ready and just edited some things. It basically downloads a game’s updates.
I’ve handled other projects before that used only Webclient to download, but this Leacher uses Backgroundworker, and so far no problem. Only this Backgroundworker uses System.ComponentModel.Progresschangedeventhandler and it does not have the bytesReceived and totalBytesToReceive options as it has in Webclient. So I can’t get the download data to show how much was downloaded and how much is missing.
Code using Webclient.Downloadprogresschangedeventargs:
private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
downloadLbl.Text = "Downloading Updates";
label1.Text = e.ProgressPercentage + "%";
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn / totalBytes * 100;
label2.Text = "Downloaded " + e.BytesReceived + " of " + e.TotalBytesToReceive;
}
If I put this above code no error appears, but when you run the program and download, the progressbar and the labels do not work because you are using Backgroundworker to download the file.
Code using Backgroundworkder Componentmodel.Progresschangedeventargs:
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
downloadLbl.Text = "Downloading Updates";
label1.Text = e.ProgressPercentage + "%";
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn / totalBytes * 100;
label2.Text = "Downloaded " + e.BytesReceived + " of " + e.TotalBytesToReceive;
}
Using this code the progressibar works and the progress in % of the label1 too, but the label2 with the download data and how much to finish do not work and Totalbytestoreceive and Bytesreceived are underlined in red with an error saying that "Progresschangedeventargs" does not contain a definition for Totalbytestoreceive/Bytesreceived.
Does anyone know any solution or gambiarra that I can do to solve this problem? Thanks!!
Why not use a Webclient.Downloadasync()?
– CypherPotato