private bool SyncServerFileDownload() { try { // 개발자모드일경우 호출X if (ApplicationConfig.Mode == "D") { OnStatusUpdate("SyncServerFileDownload", PublishProcessStatus.Download_True); } else { using (HttpRequestHelper client = new HttpRequestHelper()) { string serverPath = ApplicationConfig.ServerPublishPath; string path; string downpath = string.Empty; for (int i = 0; i < SyncResourceData.ServerConfig.Files.Count; i++) { path = ApplicationConfig.ServerPublishPath + SyncResourceData.ServerConfig.Files[i].ServerUrl; if (IsDownloadAll) { downpath = client.DownloadFile(path, TempDirectory, SyncResourceData.ServerConfig.Files[i].FileName); } else { if (GetDownloadFlag(SyncResourceData.ServerConfig.Files[i].PublishState)) { downpath = client.DownloadFile(path, TempDirectory, SyncResourceData.ServerConfig.Files[i].FileName); } else { downpath = string.Empty; } } if (string.IsNullOrEmpty(downpath)) { SyncResourceData.ServerConfig.Files[i].State = SyncFileStatus.Empty.ToString(); } else { SyncResourceData.ServerConfig.Files[i].State = SyncFileStatus.Download.ToString(); SyncResourceData.ServerConfig.Files[i].DownloadPath = downpath; } } OnStatusUpdate("SyncServerFileDownload", PublishProcessStatus.Download_True); } } } catch (Exception ex) { OnStatusUpdate("SyncServerFileDownload", PublishProcessStatus.Fail, ex.Message); } return(GetSyncStatusBoolean()); }
/// <summary> /// 下载文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_downloadFont_Click(object sender, EventArgs e) { t1 = new Thread(new ThreadStart(() => { while (true) { this.Invoke(new InvokeHandler(() => { if (downUrlQueue.Count() > 0) { string url = downUrlQueue.Dequeue(); string[] tempArray = url.Split('/'); string fileName = tempArray[tempArray.Length - 1]; HttpRequestHelper.DownloadFile(url, System.Environment.CurrentDirectory + "/font/" + fileName); tb_downLoadRecord.AppendText(System.Environment.CurrentDirectory + "/font/" + fileName + "\r\n"); } })); Thread.Sleep(100); //线程100 0.1 正好 } })); t1.Start(); }