private void ProgressChanged(DownloadProgressChangedArgs e) { if (e.TotalBytesToReceive > 0) { label1.Text = String.Format(CultureConstants.TidyInteger, "Downloading update ({0}%, {1:n} of {2:n} bytes received)...", e.ProgressPercentage, e.BytesReceived, e.TotalBytesToReceive); pbProgress.Style = ProgressBarStyle.Blocks; pbProgress.Minimum = 0; pbProgress.Maximum = 100; // Under Vista and Windows 7 there is a lag when progress bar updates too quick. // This hackish way though solves this issue (in a way) as explained in // http://stackoverflow.com/questions/977278/how-can-i-make-the-progress-bar-update-fast-enough/1214147#1214147. pbProgress.Value = e.ProgressPercentage; pbProgress.Value = (e.ProgressPercentage == 0 ? e.ProgressPercentage : e.ProgressPercentage - 1); } else { label1.Text = String.Format(CultureConstants.TidyInteger, "Downloading update ({0:n} bytes received)...", e.BytesReceived); if (pbProgress.Style != ProgressBarStyle.Marquee) { pbProgress.Style = ProgressBarStyle.Marquee; } } }
private void ProgressChangedCallback(DownloadProgressChangedArgs e) { Invoke((MethodInvoker) delegate { ProgressChanged(e); }); }