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

定义

开始异步写操作。Begins an asynchronous write operation. (请考虑改用 WriteAsync(Byte[], Int32, Int32) 方法。)(Consider using the WriteAsync(Byte[], Int32, Int32) method instead.)

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

参数

arraybuffer
Byte[]

从中写入数据的缓冲区。The buffer to write data from.

offset
Int32

buffer 中的字节偏移量,从此处开始写入。The byte offset in buffer to begin writing from.

count
Int32

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

asyncCallbackcback
AsyncCallback

可选的异步回调,在完成写入操作时调用。An optional asynchronous callback, to be called when the write operation is complete.

asyncStatestate
Object

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

返回

表示异步写入操作(可能仍处于挂起状态)的对象。An object that represents the asynchronous write operation, which could still be pending.

异常

尝试异步写入超过流的结尾的方法或发生错误的磁盘。The method tried to write asynchronously past the end of the stream, or a disk error occurred.

一个或多个自变量无效。One or more of the arguments is invalid.

在流关闭后调用方法。Methods were called after the stream was closed.

当前 DeflateStream 实现不支持写入操作。The current DeflateStream implementation does not support the write operation.

由于流已关闭,因此无法执行写入操作。The write operation cannot be performed because the stream is closed.

注解

.NET Framework 4.5.NET Framework 4.5开始,可以通过使用 WriteAsync 方法执行异步写入操作。Starting with the .NET Framework 4.5.NET Framework 4.5, you can perform asynchronous write operations by using the WriteAsync method. BeginWrite 方法仍在 .NET Framework 4.5.NET Framework 4.5 中可用以支持旧版代码;不过,您可以使用新的异步方法更轻松地实现异步 i/o 操作。The BeginWrite method is still available in the .NET Framework 4.5.NET Framework 4.5 to support legacy code; however, you can implement asynchronous I/O operations more easily by using the new async methods. 有关详细信息,请参阅异步文件 I/OFor more information, see Asynchronous File I/O.

将当前方法返回的 IAsyncResult 对象传递到 EndWrite,以确保写入完成并适当地释放资源。Pass the IAsyncResult object returned by the current method to EndWrite to ensure that the write completes and frees resources appropriately. 为此,可以使用 BeginWrite 调用的相同代码,也可以在传递给 BeginWrite的回调中执行此操作。You can do this either by using the same code that called BeginWrite or in a callback passed to BeginWrite. 如果在异步写入操作过程中发生错误,则在使用此方法返回的 IAsyncResult 调用 EndWrite 之前,将不会引发异常。If an error occurs during an asynchronous write operation, an exception will not be thrown until EndWrite is called with the IAsyncResult returned by this method.

如果流可写,则在流的末尾写入会扩展流。If a stream is writable, writing at the end of the stream expands the stream.

发出异步读取或写入操作时,将更新流中的当前位置,而不是在 i/o 操作完成时进行更新。The current position in the stream is updated when you issue the asynchronous read or write operation, not when the I/O operation completes. 多个同时进行的异步请求会导致不确定请求完成顺序。Multiple simultaneous asynchronous requests render the request completion order uncertain.

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

如果流已关闭或传递的参数无效,则会立即从 BeginWrite引发异常。If a stream is closed or you pass an invalid argument, exceptions are thrown immediately from BeginWrite. 在异步写入请求期间发生的错误(例如,i/o 请求过程中的磁盘故障)会在线程池线程上发生,并在调用 EndWrite时引发异常。Errors that occur during an asynchronous write request, such as a disk failure during the I/O request, occur on the thread pool thread and throw exceptions when calling EndWrite.

适用于