HttpClientHelper.HttpDownloadProgress downloadProgress; //下载进度回调给用户回调的 public HttpMutilThreadDownload(string url, string fileName, int threadNum, int bufsize, HttpClientHelper.HttpDownloadProgress progress) { this.Url = url; this.FileName = fileName; this.downloadProgress = progress; this.BufferSize = bufsize; this.ThreadNum = threadNum; HasMerge = 0; ThreadStatus = false; CpuLogicCount = Computer.Instance().GetLogicCpuCount() + 1; threadSeam = new Semaphore(CpuLogicCount, CpuLogicCount); byteCopiedQueue = new Queue <long>(); try//这里Get同步 { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.Url); WebResponse resp = request.GetResponse(); //获得响应头 FileSizeAll = resp.ContentLength; //文件长 if (FileSizeAll <= 0) { progress(0, 0, HttpClientHelper.HttpDownloadState.ERROR, "没有获得到文件长度,网络出现波动."); } request.Abort(); //请求终止 } catch (WebException e) { progress(0, 0, HttpClientHelper.HttpDownloadState.ERROR, e.Message.ToString()); return; } Init(FileSizeAll); //初始化 }
public DownloadRecvice(int threadid, HttpMutilThreadDownload obj, HttpClientHelper.HttpDownloadProgress progress) { dataObj = obj; ThreadId = threadid; downloadProgress = progress; }