PipeStream.BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object) 方法

定义

开始执行异步写入操作。Begins an asynchronous write operation.

public:
 override IAsyncResult ^ BeginWrite(cli::array <System::Byte> ^ buffer, int offset, int count, AsyncCallback ^ callback, System::Object ^ state);
[System.Security.SecurityCritical]
public override IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback callback, object state);
override this.BeginWrite : byte[] * int * int * AsyncCallback * obj -> IAsyncResult
Public Overrides Function BeginWrite (buffer As Byte(), offset As Integer, count As Integer, callback As AsyncCallback, state As Object) As IAsyncResult

参数

buffer
Byte[]

包含要写入当前流的数据的缓冲区。The buffer that contains the data to write to the current stream.

offset
Int32

buffer 中的从零开始的字节偏移量,从此处开始将字节复制到当前流。The zero-based byte offset in buffer at which to begin copying bytes to the current stream.

count
Int32

要写入的最大字节数。The maximum number of bytes to write.

callback
AsyncCallback

异步写操作完成后调用的方法。The method to call when the asynchronous write operation is completed.

state
Object

用户提供的对象,用于将此特定异步写入请求与其他请求区分开来。A user-provided object that distinguishes this particular asynchronous write request from other requests.

返回

一个引用异步写操作的 IAsyncResult 对象。An IAsyncResult object that references the asynchronous write operation.

属性

异常

buffernullbuffer is null.

offset 小于 0。offset is less than 0.

- 或 --or- count 小于 0。count is less than 0.

count 大于 buffer 中可用的字节数。count is greater than the number of bytes available in buffer.

管道已关闭。The pipe is closed.

管道不支持写入操作。The pipe does not support write operations.

管道已断开连接,正在等待连接,或尚未设置句柄。The pipe is disconnected, waiting to connect, or the handle has not been set.

管道已损坏或出现其他 I/O 错误。The pipe is broken or another I/O error occurred.

注解

对于每次调用 BeginWrite,都必须调用 EndWrite 一次。EndWrite must be called once for every call to BeginWrite. 这可以在调用 BeginWrite 的同一代码中完成,也可以在传递给 BeginWrite的回调中完成。This can be done either in the same code that called BeginWrite or in a callback that is passed to BeginWrite.

使用 CanWrite 属性来确定当前 PipeStream 对象是否支持写入操作。Use the CanWrite property to determine whether the current PipeStream object supports write operations.

如果关闭管道或将无效参数传递到 BeginWrite,则会立即引发相应的异常。If the pipe is closed or an invalid argument is passed to BeginWrite, the appropriate exceptions are raised immediately. 在执行请求的线程池线程上发生异步写入请求期间发生的错误。Errors that occur during an asynchronous write request occur on the thread pool thread that is performing the request. 当代码调用 EndWrite 方法时,将引发异常。The exceptions are raised when the code calls the EndWrite method.

适用于