diff --git a/Updates/FormUpdateDownload.Designer.cs b/Updates/FormUpdateDownload.Designer.cs index 75e30310..604c90c9 100644 --- a/Updates/FormUpdateDownload.Designer.cs +++ b/Updates/FormUpdateDownload.Designer.cs @@ -82,6 +82,7 @@ private void InitializeComponent() { this.Controls.Add(this.labelDescription); this.Controls.Add(this.btnCancel); this.Controls.Add(this.progressDownload); + this.DoubleBuffered = true; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; diff --git a/Updates/FormUpdateDownload.cs b/Updates/FormUpdateDownload.cs index 61859db1..7cb2ff82 100644 --- a/Updates/FormUpdateDownload.cs +++ b/Updates/FormUpdateDownload.cs @@ -28,18 +28,17 @@ public enum Status{ public FormUpdateDownload(UpdateInfo info){ InitializeComponent(); - this.webClient = new WebClient{ Proxy = null }; - this.webClient.Headers[HttpRequestHeader.UserAgent] = BrowserUtils.HeaderUserAgent; + Text = "Updating "+Program.BrandName; + labelDescription.Text = "Downloading version "+info.VersionTag+"..."; this.updateInfo = info; this.UpdateStatus = Status.Waiting; - webClient.DownloadProgressChanged += webClient_DownloadProgressChanged; - webClient.DownloadFileCompleted += webClient_DownloadFileCompleted; - - Text = "Updating "+Program.BrandName; - labelDescription.Text = "Downloading version "+info.VersionTag+"..."; - + this.webClient = new WebClient{ Proxy = null }; + this.webClient.Headers[HttpRequestHeader.UserAgent] = BrowserUtils.HeaderUserAgent; + this.webClient.DownloadProgressChanged += webClient_DownloadProgressChanged; + this.webClient.DownloadFileCompleted += webClient_DownloadFileCompleted; + Disposed += (sender, args) => this.webClient.Dispose(); } @@ -48,15 +47,24 @@ private void FormUpdateDownload_Shown(object sender, EventArgs e){ } private void btnCancel_Click(object sender, EventArgs e){ - webClient.CancelAsync(); - btnCancel.Enabled = false; + if (webClient.IsBusy){ + webClient.CancelAsync(); + btnCancel.Enabled = false; + } + else{ + UpdateStatus = Status.Cancelled; + Close(); + } } private void FormUpdateDownload_FormClosing(object sender, FormClosingEventArgs e){ if (UpdateStatus == Status.Waiting){ - e.Cancel = true; - webClient.CancelAsync(); UpdateStatus = e.CloseReason == CloseReason.UserClosing ? Status.Cancelled : Status.Manual; // manual will exit the app + + if (webClient.IsBusy){ + webClient.CancelAsync(); + e.Cancel = true; + } } }