异步流读取器和写入器(带进度支持)
AsyncStreaming

引言
AsyncStreaming
是一个用于异步流读取和写入的类库。 AsyncStreaming
支持读取和写入的进度报告。
结构
使用 AsynStreamReader
和 AsyncStreamWriter
的常用类
AsyncStreamException
- 此类表示异步流处理期间发生的错误。AsyncStreamStateChangeArgs
- 此类为状态更改事件提供数据。AsyncStreamErrorEventArgs
- 此类为错误事件提供数据。AsyncStreamState
- 此枚举指定用于指示AsyncStreaming
状态的标识符。
可能的状态
- 无
- 就绪 - 当流准备好启动时发生此状态。
- 已启动 - 当流已启动时发生此状态。
- 已暂停 - 当流已暂停时发生此状态。
- 已停止 - 当流已停止时发生此状态。
- 已完成 - 当流已完成时发生此状态。
- 错误 - 当发生流异常时发生此状态。
AsyncStreamReader

BaseAsyncStreamReader
- 异步读取的基本功能。因此,您可以轻松使用此类在您自己的读取类中实现基本功能。AsyncStreamReader
- 从BaseAsyncStreamReader
类扩展并添加构造函数的类。
Public
方法
StartRead()
- 启动异步读取操作PauseRead()
– 暂停异步读取操作ResumeRead()
– 恢复已暂停的异步读取操作StopRead()
– 停止异步读取操作
事件
OnReadedBytes
– 当进度增加百分之一时发生OnEndRead
– 当所有字节都被读取时发生OnError
– 当发生AsyncStreamExcpetion
时发生OnStateChanged
– 当AsyncStreamReader
的状态改变时发生
构造函数
/// <summary>
/// Implements a System.IO.TextReader that reads characters from a byte stream
/// in a particular encoding.
/// </summary>
/// <param name="path">The complete file path to be read.</param>
public AsyncStreamReader(string path)
AsyncStreamWriter

BaseAsyncStreamWriter
– 异步写入的基本功能。因此,您可以轻松使用此类在您自己的写入类中实现基本功能。AsyncStreamWriter
– 从BaseAsyncStreamWriter
类扩展并添加构造函数的类。
Public
方法
StartWrite()
– 开始异步写入操作PauseWrite()
– 暂停异步写入操作ResumeWrite()
– 恢复已暂停的异步写入操作StopWrite()
– 停止异步写入操作
事件
OnStateChanged
– 当AsyncStreamWriter
的状态改变时发生OnWritedBytes
– 当进度增加百分之一时发生OnEndWrite
– 当所有字节都被写入时发生OnError
- 当发生AsyncException
时发生
构造函数
/// <summary>
/// Initializes a new empty instance of the AsyncStreaming.AsyncStreamWriter class.
/// </summary>
public AsyncStreamWriter()
/// <summary>
/// Initializes a new instance of the AsyncStreaming.AsyncStreamWriter
/// class for the specified
/// file on the specified path, using the default encoding.
/// </summary>
/// <param name="outputPath">The complete file path to write to.
/// Path can be a file name.</param>
public AsyncStreamWriter(string outputPath)
/// <summary>
/// Initializes a new instance of the AsyncStreaming.AsyncStreamWriter
/// class for the specified
/// file on the specified path, using the default encoding.
/// </summary>
/// <param name="outputPath">The complete file path to write to.
/// Path can be a file name.</param>
/// <param name="buffer">The string to write to the stream.
/// If value is null, nothing is written.</param>
/// <param name="encoding">The string encoding to use.</param>
public AsyncStreamWriter(string outputPath, string buffer, Encoding encoding)
/// <summary>
/// Initializes a new instance of the AsyncStreaming.AsyncStreamWriter
/// class for the specified
/// file on the specified path, using the default encoding.
/// </summary>
/// <param name="outputPath">The complete file path to write to.
/// Path can be a file name.</param>
/// <param name="buffer">The string to write to the stream.
/// If value is null, nothing is written.</param>
public AsyncStreamWriter(string outputPath, string buffer)
/// <summary>
/// Initializes a new instance of the AsyncStreaming.AsyncStreamWriter
/// class for the specified
/// file on the specified path, using the default encoding.
/// </summary>
/// <param name="outputPath">The complete file path to write to.
/// Path can be a file name.</param>
/// <param name="buffer">An array of bytes.
/// This method copies count bytes from buffer to the current stream.</param>
public AsyncStreamWriter(string outputPath, byte[] buffer)
历史
- 2009 年 4 月 21 日:初始发布