示例#1
0
	private void x_ExceptionOccurrs(Microshaoft.Utils.HttpWebClient Sender, Microshaoft.Utils.ExceptionEventArgs e)
	{
		System.Console.WriteLine(e.Exception.Message);
		//发生异常重新下载相当于断点续传,你可以自己自行选择处理方式或自行处理
		Microshaoft.Utils.HttpWebClient x = new Microshaoft.Utils.HttpWebClient();
		x.DownloadFileChunk(this._F, this._f, e.DownloadState.Position, e.DownloadState.Length);
		e.ExceptionAction = Microshaoft.Utils.ExceptionActions.Ignore;
	}
示例#2
0
	private void x_DataReceive(Microshaoft.Utils.HttpWebClient Sender, Microshaoft.Utils.DownLoadEventArgs e)
	{
		if (!this.b)
		{
			lock (_SyncLockObject)
			{
				if (!this.b)
				{
					System.Console.Write(System.DateTime.Now.ToString() + " 已接收数据: ");
					//System.Console.Write( System.DateTime.Now.ToString() + " 已接收数据: ");
					this.b = true;
				}
			}
		}
		string f = e.DownloadState.FileName;
		if (e.DownloadState.AttachmentName != null)
			f = System.IO.Path.GetDirectoryName(f) + @"\" + e.DownloadState.AttachmentName;

		this._f = f;

		using (System.IO.FileStream sw = new System.IO.FileStream(f, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite))
		{
			sw.Position = e.DownloadState.Position;
			sw.Write(e.DownloadState.Data, 0, e.DownloadState.Data.Length);
			sw.Close();
		}
		string s = System.DateTime.Now.ToString();
		lock (_SyncLockObject)
		{
			this.i += e.DownloadState.Data.Length;
			System.Console.Write(bs + "\b\b\b\b\b\b\b\b\b\b" + i + " / " + Sender.FileLength + " 字节数据 " + s);
			//System.Console.Write(bs + i + " 字节数据 " + s);
			this.bs = new string('\b', Digits(i) + +Digits(Sender.FileLength) + s.Length);
		}
	}