private void OutDownload(ModelDownLoadImg d) { this.Invoke(new MethodInvoker(() => { try { var file = new FileInfo(d.LocalImg); if (!Directory.Exists(file.Directory.FullName)) { Directory.CreateDirectory(file.Directory.FullName); } if (File.Exists(d.LocalImg)) { return; } DownLoadFile(d.RemoteImg, d.LocalImg); this.txtLogView.AppendText($"任务ID:{d.TaskId} 远程图片:{d.RemoteImg} 本地图片:{d.LocalImg} 下载完成!"); this.txtLogView.AppendText("\r\n"); } catch (Exception ex) { this.txtLogView.AppendText($"任务ID:{d.TaskId} 远程图片:{d.RemoteImg} 本地图片:{d.LocalImg} 失败!{ex.Message}"); this.txtLogView.AppendText("\r\n"); } })); }
public static ModelDownLoadImg DequeueImg() { ModelDownLoadImg d = null; lock (lockObj) { d = Q_DownImgResource.Dequeue(); } if (d != null) { return(d); } return(null); }
public static void AddImg(int TaskId, string localPic, string remotePic, int stepTime) { var d = new ModelDownLoadImg(); d.TaskId = TaskId; d.LocalImg = localPic; d.RemoteImg = remotePic; d.StepTime = stepTime; lock (lockObj) { Q_DownImgResource.Enqueue(d); } }
void th_WorkMethod(int taskindex, int threadindex) { while (true) { ModelDownLoadImg d = null; lock (QueueImgHelper.lockObj) { if (QueueImgHelper.Q_DownImgResource.Count > 0) { d = QueueImgHelper.Q_DownImgResource.Dequeue(); } } if (d != null) { OutDownload(d); Thread.Sleep(d.StepTime); } } }