資源簡介
【版本已更新:http://download.csdn.net/source/2632090】
(說明:這是一個輸出DLL的項目,需要在其他項目添加引用使用,如果要直接運行,請自行添加入口函數)
支持多個下載任務,分塊多線程下載,斷點續傳。
(對比上個版本,完成了遺留的功能,修改了事件觸發過程及處理方式,重新整理了代碼及注釋)
內含兩個窗體,可視為演示程序。
DownloadForm 下載窗體,含相關事件處理及交互控制
TestForm1 調用DownloadForm下載測試
Events.txt 描述事件觸發及處理流程
希望寫的能看懂:
一般實時的事件需要在當前子線程處理;而涉及到線程控制的事件(如結束下載線程),為了確保事件處理能正常執行,則才采用主線程代理的方式處理。
這種代理方式是由于系統中直接操作線程引發的,如果改用系統線程池的話,可以重新定制處理流程。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Text;
namespace?DownloadMag
{
????#region?序列化存儲:下載任務列表
????///?
????///?下載任務列表
????///?用于序列化存儲任務信息
????///?
????public?class?DTaskDataList
????{
????????public?DTaskDataList()
????????{
????????????m_TaskDataList?=?new?List();
????????}
????????[System.xml.Serialization.xmlArrayItem(“TaskList“?typeof(DTaskData))]
????????private?List?m_TaskDataList;
????????public?List?TaskDataList
????????{
????????????get?{?return?m_TaskDataList;?}
????????????set?{?m_TaskDataList?=?value;?}
????????}
????}
????#endregion
????#region?任務狀態
????///?
????///?下載任務狀態
????///?
????public?enum?DTaskState
????{
????????///?
????????///?停止
????????///?
????????Stopped?=?0
????????///?
????????///?已啟動
????????///?
????????Started
????????///?
????????///?等待
????????///?
????????Waiting
????????///?
????????///?已完成
????????///?
????????Completed
????????///?
????????///?失敗
????????///?
????????Failed
????????///?
????????///?取消
????????///?
????????Aborted
????}
????///?
????///?下載線程狀態
????///?
????public?enum?WorkThreadState
????{
????????///?
????????///?停止
????????///?
????????Stopped?=?0
????????///?
????????///?已啟動
????????///?
????????Started
????????///?
????????///?已完成
????????///?
????????Completed
????????///?
????????///?失敗
????????///?
????????Failed
????}
????#endregion
????#region?事件相關定義
????public?class?TaskInitializedEventArgs?:?EventArgs
????{
????????///?
????????///?
????????///?
????????///?下載數據/文件大小
????????public?TaskInitializedEventArgs(long?length)
????????{
????????????m_length?=?length;
????????}
????????private?long?m_length;
????????///?
????????///?下載數據大小
????????///?
????????public?long?Length
????????{
????????????get?{?return?m_length;?}
????????????set?{?m_length?=?value;?}
????????}
????}
????public?class?WriteToStreamEventArgs?:?EventArgs
????{
????????///?
????????///?
????????///?
????????///?數據大小
????????public?WriteToStreamEventArgs(long?length)
????????{
????????????m_length?=?length;
????????}
????????private?long?m_length;
????????///?
????????///?數據大小
????????///?
????????public?long?Length
????????{
????????????get?{?return?m_length;?}
????????????set?{?m_length?=?value;?}
????????}
????}
????public?class?TaskThreadErrorEventArgs?:?EventArgs
????{
????????///?
????????///?
????????///?
????????///?捕獲的異常
????????public?TaskThreadErrorEventArgs(Exception?erro
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????6015??2008-05-12?12:53??DownloadMag\ClassLibrary.cs
?????文件???????2380??2008-05-15?15:41??DownloadMag\CRC32.cs
?????文件??????10063??2008-05-15?15:56??DownloadMag\Download.cs
?????文件???????4626??2008-05-15?16:35??DownloadMag\DownloadMag.csproj
?????文件????????911??2008-05-15?16:15??DownloadMag\DownloadMag.sln
????..A..H.?????90112??2008-05-15?16:36??DownloadMag\DownloadMag.suo
?????文件??????27212??2008-05-15?15:49??DownloadMag\DTask.cs
?????文件??????26218??2008-05-15?14:30??DownloadMag\DTaskConfig.cs
?????文件???????1353??2008-01-14?15:20??DownloadMag\DTaskConfigData.cs
?????文件???????4154??2008-05-15?15:52??DownloadMag\DTaskData.cs
?????文件??????17426??2008-05-15?15:49??DownloadMag\DTaskMag.cs
?????文件???????1529??2008-01-15?17:37??DownloadMag\EventProxy.cs
?????文件???????3113??2008-05-12?10:42??DownloadMag\Events.txt
?????文件??????17062??2008-05-15?16:32??DownloadMag\Forms\DownloadForm.cs
?????文件??????25425??2008-05-15?16:32??DownloadMag\Forms\DownloadForm.Designer.cs
?????文件??????18120??2008-05-15?16:32??DownloadMag\Forms\DownloadForm.resx
?????文件??????10128??2007-11-07?14:10??DownloadMag\Forms\MsgBox.cs
?????文件??????15414??2008-05-12?14:23??DownloadMag\Forms\MsgBox.Designer.cs
?????文件??????47706??2007-11-07?14:10??DownloadMag\Forms\MsgBox.resx
?????文件???????1786??2008-05-15?16:32??DownloadMag\Forms\TestForm1.cs
?????文件???????3386??2008-05-15?16:28??DownloadMag\Forms\TestForm1.Designer.cs
?????文件???????5814??2008-05-15?16:28??DownloadMag\Forms\TestForm1.resx
?????文件???????1406??2005-08-03?09:36??DownloadMag\images\down.ico
?????文件???????1406??2005-08-03?09:36??DownloadMag\images\ok.ico
?????文件???????1406??2005-08-03?09:36??DownloadMag\images\point_blue.ico
?????文件???????1406??2005-08-03?09:36??DownloadMag\images\point_cyan.ico
?????文件???????1406??2005-08-03?09:36??DownloadMag\images\point_green.ico
?????文件???????1406??2005-08-03?09:36??DownloadMag\images\point_red.ico
?????文件???????1406??2005-08-03?09:36??DownloadMag\images\point_yellow.ico
?????文件???????1406??2005-08-03?09:36??DownloadMag\images\right.ico
............此處省略13個文件信息
- 上一篇:C#多任務多線程組件源代碼
- 下一篇:C#器Demo
評論
共有 條評論