I am trying to download a file with a webclient from a server. This works very good. But when I try to show the download progress in a progress bar, it does not give me any progress to see.
I am trying to download the file with the DownloadFileAsync-method to have an own thread for it all in order to prevent performance problems or freezes.
I declared the WebClient outside any subs or events:
private WebClient updateDownloader = new WebClient();
This looks like that in the Form.Shown-Event:
updateDownloader.DownloadFileAsync(new Uri(UriGoesHere), PathToSave);
It is in a Try-Block.
I created a sub like that to show the progress to the progressbar:
private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}
In the Form-Load-Event I created the eventhandler:
updateDownloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
This should work in theory, but it does not, I already visited MSDN and saw some information that only some methods are working, but implementing this did not help.
It never reaches this one. What am I doing wrong? If you need some more code parts, tell me.