private void Download(string path, string dir, string filename, int id = 0)
        {
            try
            {
                DownMsg downMsg = new DownMsg();
                downMsg.Id  = id;
                downMsg.Tag = 0;
                doSendMsg(downMsg);

                FileDownloader loader = new FileDownloader(path, dir, filename, ThreadNum);
                loader.data.Clear();
                downMsg.Tag    = DownStatus.Start;
                downMsg.Length = (int)loader.getFileSize();;
                doSendMsg(downMsg);

                DownloadProgressListener linstenter = new DownloadProgressListener(downMsg);
                linstenter.doSendMsg = new DownloadProgressListener.dlgSendMsg(doSendMsg);
                loader.download(linstenter);
            }
            catch (Exception ex)
            {
                Log4net.log4netCreate(typeof(DownLoadFileGeneral), log4netPath).Error("错误信息: " + ex.Message);
                Console.WriteLine(ex.Message);
            }
        }
 /// <summary>
 /// 情动线程下载
 /// </summary>
 private void DownLoadFileChange(DownMsg downMsg)
 {
     if (downMsg.Tag == DownStatus.Error || downMsg.Tag == DownStatus.End)
     {
         StartDown(ThreadNum);
     }
 }
        public void OnDownloadSize(long size)
        {
            if (downMsg == null)
            {
                DownMsg downMsg = new DownMsg();
            }


            //下载速度
            if (downMsg.Size == 0)
            {
                downMsg.Speed = size;
            }
            else
            {
                downMsg.Speed = (float)(size - downMsg.Size);
            }

            if (downMsg.Speed == 0)
            {
                downMsg.Surplus = -1; downMsg.SurplusInfo = "未知";
            }
            else
            {
                downMsg.Surplus = ((downMsg.Length - downMsg.Size) / downMsg.Speed);
            }

            downMsg.Size = size; //下载总量

            if (size == downMsg.Length)
            {
                //下载完成
                downMsg.Tag         = DownStatus.End;
                downMsg.SpeedInfo   = "0 K";
                downMsg.SurplusInfo = "已完成";
            }
            else
            {
                //下载中
                downMsg.Tag = DownStatus.DownLoad;
            }


            if (doSendMsg != null)
            {
                doSendMsg(downMsg);                   //通知具体调用者下载进度
            }
        }
 public DownloadProgressListener(DownMsg downmsg)
 {
     this.downMsg = downmsg;
 }