From cf567144a32fe2d01892249325ba6acbbd46d12d Mon Sep 17 00:00:00 2001 From: wule Date: Wed, 26 Aug 2026 15:54:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E7=A8=8B=E5=BA=8F=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Update/Update/MainForm.cs | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/Update/Update/MainForm.cs b/Update/Update/MainForm.cs index ae754e5..d13581f 100644 --- a/Update/Update/MainForm.cs +++ b/Update/Update/MainForm.cs @@ -6,6 +6,8 @@ using System.Drawing; using System.IO; using System.IO.Compression; using System.Linq; +using System.Net; +using System.Reflection.Emit; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -69,22 +71,37 @@ namespace Update progressBar1.Visible = true; progressBar1.Maximum = 100;//fileNameArr.Count(); progressBar1.Value = 0; - new TaskFactory().StartNew(() => + Task.Run(async() => { string tempFile = upTempPath + "\\" + Program.updateUrl.Substring(Program.updateUrl.LastIndexOf("/") + 1); - bool result = Program.DownloadFile(Program.updateUrl, tempFile); + //bool result = Program.DownloadFile(Program.updateUrl, tempFile); - while (true) + //while (true) + //{ + // Invoke(new Action(() => + // { + // progressBar1.Value = Program.progress; + // })); + // if (Program.progress == 100) + // break; + //} + + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + using (var downloadClient = new WebClient()) { - Invoke(new Action(() => + downloadClient.Proxy = null; + + downloadClient.DownloadProgressChanged += (s, args) => { - progressBar1.Value = Program.progress; - })); - if (Program.progress == 100) - break; + Invoke(new Action(() => { progressBar1.Value = args.ProgressPercentage; })); + + }; + + await downloadClient.DownloadFileTaskAsync(new Uri(Program.updateUrl), tempFile); } - if (result) + if (1 == 1) + //if (result) { ZipFile.ExtractToDirectory(tempFile, upTempPath); File.Delete(tempFile);