/// <summary> /// 下載方法 /// </summary> private UpdateWork DownLoad() { //截取文件名 //構造文件完全限定名,准備將網絡流下載為本地文件 using (WebClient web = new WebClient()) { foreach (var item in UpdateVerList) { try { LogTool.AddLog("更新程序:下載更新包文件" + item.ReleaseVersion); web.DownloadFile(item.ReleaseUrl, tempPath + item.ReleaseVersion + ".zip"); OnUpdateProgess?.Invoke(60 / UpdateVerList.Count); } catch (Exception ex) { LogTool.AddLog("更新程序:更新包文件" + item.ReleaseVersion + "下載失敗,本次停止更新,異常信息:" + ex.Message); throw ex; } } return this; } }
像語句里面的?.的意思是:如果前面的OnUpdateProgess不為空,則執行后面的Invoke,以此類推。