From 8a34e8c5e1a16e81a9ea585cd5b33d947f93d306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E9=B9=8F?= <278334996@qq.com> Date: Sat, 29 Sep 2018 19:30:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8B=E8=BD=BD=E7=A9=BA?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=97=A0=E5=93=8D=E5=BA=94=E7=9A=84BUG.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WebClient.DownloadProgressChanged在下载0kb空文件时就算完成了也不会触发,所以需要改成DownloadFileCompleted --- .../Scripts/Manager/ThreadManager.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Assets/LuaFramework/Scripts/Manager/ThreadManager.cs b/Assets/LuaFramework/Scripts/Manager/ThreadManager.cs index 3a9556a71..0858a67dd 100644 --- a/Assets/LuaFramework/Scripts/Manager/ThreadManager.cs +++ b/Assets/LuaFramework/Scripts/Manager/ThreadManager.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Net; using System; +using System.ComponentModel; public class ThreadEvent { public string Key; @@ -102,6 +103,7 @@ void OnDownloadFile(List evParams) { using (WebClient client = new WebClient()) { sw.Start(); client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); + client.DownloadFileCompleted += new AsyncCompletedEventHandler(ProgressFinish); client.DownloadFileAsync(new System.Uri(url), currDownFile); } } @@ -118,14 +120,15 @@ private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e) string value = string.Format("{0} kb/s", (e.BytesReceived / 1024d / sw.Elapsed.TotalSeconds).ToString("0.00")); NotiData data = new NotiData(NotiConst.UPDATE_PROGRESS, value); if (m_SyncEvent != null) m_SyncEvent(data); - - if (e.ProgressPercentage == 100 && e.BytesReceived == e.TotalBytesToReceive) { - sw.Reset(); - - data = new NotiData(NotiConst.UPDATE_DOWNLOAD, currDownFile); - if (m_SyncEvent != null) m_SyncEvent(data); - } } + + void ProgressFinish(object sender, AsyncCompletedEventArgs e) + { + sw.Reset(); + NotiData data = new NotiData(NotiConst.UPDATE_DOWNLOAD, currDownFile); + if (m_SyncEvent != null) + m_SyncEvent(data); + } /// /// 调用方法