資源簡介
注意:
在斷點續(xù)傳的過程中,我們以 byte 為單位下載、合并文件,如果整個過程中稍有沒有處理好的異常,可能最后得到的文件就和源文件不太一樣。因此最好是能夠?qū)ο螺d好的文件進行一次校驗。可這也是最難、最不容易實現(xiàn)的。因為它需要服務(wù)器端的支持,比如服務(wù)器端在提供一個可下載文件的同時提供該文件的 MD5 hash。當(dāng)然,如果服務(wù)器端也是我們自己創(chuàng)建的,我們就可以去實現(xiàn)它
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Diagnostics;
using?System.IO;
using?System.Linq;
using?System.Net;
using?System.Text;
namespace?BreakpointResume
{
????internal?class?DownloadManager
????{
????????private?Stopwatch?_downloadStopWatch?=?null;
????????private?bool?_cancelDownload?=?false;
????????private?BackgroundWorker?_bgWorker?=?null;
????????private?static?readonly?int?BufferSize?=?32768;
????????public?DownloadManager(BackgroundWorker?bgWorker)
????????{
????????????_bgWorker?=?bgWorker;
????????????_downloadStopWatch?=?new?Stopwatch();
????????}
????????public?bool?DownloadFile(string?url?string?fileName)
????????{
????????????bool?isDownloadSuccessfully?=?false;
????????????try
????????????{
???
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????4235??2016-04-29?15:07??BreakpointResume\BreakpointResume.csproj
?????文件????????1000??2016-05-28?15:04??BreakpointResume\BreakpointResume.sln
?????文件????????8654??2016-05-28?15:08??BreakpointResume\DownloadManager.cs
?????文件????????3258??2016-05-28?17:25??BreakpointResume\DownloadProcessForm.cs
?????文件????????3853??2016-04-29?15:30??BreakpointResume\DownloadProcessForm.Designer.cs
?????文件????????5817??2016-04-29?15:30??BreakpointResume\DownloadProcessForm.resx
?????文件?????????551??2016-04-29?15:18??BreakpointResume\Form1.cs
?????文件????????2130??2016-04-29?15:01??BreakpointResume\Form1.Designer.cs
?????文件????????5817??2016-04-29?15:01??BreakpointResume\Form1.resx
?????文件????????1276??2016-04-29?15:07??BreakpointResume\Log.cs
?????文件?????????508??2016-04-29?14:58??BreakpointResume\Program.cs
?????目錄???????????0??2016-05-28?14:22??BreakpointResume\Properties\
?????文件????????1444??2016-04-29?14:58??BreakpointResume\Properties\AssemblyInfo.cs
?????文件????????2862??2016-04-29?14:58??BreakpointResume\Properties\Resources.Designer.cs
?????文件????????5612??2016-04-29?14:58??BreakpointResume\Properties\Resources.resx
?????文件????????1103??2016-04-29?14:58??BreakpointResume\Properties\Settings.Designer.cs
?????文件?????????249??2016-04-29?14:58??BreakpointResume\Properties\Settings.settings
?????文件????????1223??2016-04-29?15:07??BreakpointResume\Util.cs
- 上一篇:C# WinINet 文件
- 下一篇:asp.net 分頁
評論
共有 條評論