资源简介
使用BackgroundWorker 实现文件下载、异步提示
准备做一个可视化的WinForm界面,这就需要反映文件下载进度,要达到这个实时报告进度的功能,就需要进行异步操作,可以通过线程或BackgroundWorker 类去实现, 由于BackgroundWorker 类是.net2.0新增的组件类,所以想体验一下,以后面的文章中将会给出使用线程的方法。
详细信息见:http://blog.csdn.net/wguorun/archive/2008/10/30/3183863.aspx

代码片段和文件信息
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.IO;
namespace FtpClient
{
///
/// FTP 操作类
///
public class FTP
{
private string strRemoteHost;
private int strRemotePort;
private string strRemotePath;
private string strRemoteUser;
private string strRemotePass;
private Boolean bConnected;
#region 内部变量
///
/// 服务器返回的应答信息(包含应答码)
///
private string strMsg;
///
/// 服务器返回的应答信息(包含应答码)
///
private string strReply;
///
/// 服务器返回的应答码
///
private int iReplyCode;
///
/// 进行控制连接的socket
///
private Socket socketControl;
///
/// 传输模式
///
private TransferType trType;
///
/// 传输模式:二进制类型、ASCII类型
///
public enum TransferType
{
///
/// Binary
///
Binary
///
/// ASCII
///
ASCII
};
///
/// 接收和发送数据的缓冲区
///
private static int BLOCK_SIZE = 512;
Byte[] buffer = new Byte[BLOCK_SIZE];
///
/// 编码方式
///
Encoding ASCII = Encoding.Default;
#endregion
#region 内部函数
#region 构造函数
///
/// 缺省构造函数
///
public FTP()
{
strRemoteHost = ““;
strRemotePath = ““;
strRemoteUser = ““;
strRemotePass = ““;
strRemotePort = 21;
bConnected = false;
}
///
/// 构造函数
///
/// The remote host.
/// The remote path.
/// The remote user.
/// The remote pass.
/// The remote port.
public FTP(string remoteHost string remotePath string remoteUser string remotePass int remotePort)
{
strRemoteHost = remoteHost;
strRemotePath = remotePath;
strRemoteUser = remoteUser;
strRemotePass = remotePass;
strRemotePort = remotePort;
Connect();
}
///
/// Initializes a new instance of the class.
///
/// The remote host.
/// The remote path.
///
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 0 2008-10-28 17:22 bin\Debug\ex081028.log
文件 0 2008-10-29 09:48 bin\Debug\ex081029.log
文件 0 2008-10-30 12:53 bin\Debug\ex081030.log
文件 27648 2008-10-29 10:21 bin\Debug\FtpClient.exe
文件 75264 2008-10-29 10:21 bin\Debug\FtpClient.pdb
文件 14328 2008-10-30 09:59 bin\Debug\FtpClient.vshost.exe
文件 490 2007-07-21 02:33 bin\Debug\FtpClient.vshost.exe.manifest
文件 720 2008-10-30 09:59 obj\Debug\FtpClient.csproj.FileListAbsolute.txt
文件 1117 2008-10-29 10:20 obj\Debug\FtpClient.csproj.GenerateResource.Cache
文件 27648 2008-10-29 10:21 obj\Debug\FtpClient.exe
文件 180 2008-10-29 10:20 obj\Debug\FtpClient.FtpDownLoadForm.resources
文件 180 2008-10-29 10:20 obj\Debug\FtpClient.FtpWebResponseDemo.resources
文件 75264 2008-10-29 10:21 obj\Debug\FtpClient.pdb
文件 180 2008-10-29 10:20 obj\Debug\FtpClient.Properties.Resources.resources
文件 1374 2008-10-06 09:33 Properties\AssemblyInfo.cs
文件 2868 2008-10-06 09:33 Properties\Resources.Designer.cs
文件 5612 2008-10-06 09:33 Properties\Resources.resx
文件 1094 2008-10-06 09:33 Properties\Settings.Designer.cs
文件 249 2008-10-06 09:33 Properties\Settings.settings
文件 28840 2008-10-29 10:18 FTP.cs
文件 3842 2008-10-29 10:20 FtpClient.csproj
文件 7408 2008-10-30 15:07 FtpDownLoadForm.cs
文件 11077 2008-10-29 10:20 FtpDownLoadForm.Designer.cs
文件 6229 2008-10-29 10:00 FtpDownLoadForm.resx
文件 1418 2008-10-28 16:16 FtpState.cs
文件 5468 2008-10-29 10:19 FtpWebResponseDemo.cs
文件 8544 2008-10-29 10:19 FtpWebResponseDemo.Designer.cs
文件 6427 2008-10-28 15:06 FtpWebResponseDemo.resx
文件 480 2008-10-29 10:20 Program.cs
目录 0 2008-10-30 15:05 obj\Debug\Refactor
............此处省略9个文件信息
- 上一篇:C# winform 朗读输入文本
- 下一篇:BarScan条形码扫描源码c#
相关资源
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
- 基于c#的实验室设备管理系统621530
- C# 使用ListView控件实现图片浏览器(源
- C#简单窗体聊天程序
- C#指纹识别系统程序 报告
- c# 高校档案信息管理系统
评论
共有 条评论