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

定義

開始非同步的寫入作業。 (請考慮用 WriteAsync(Byte[], Int32, Int32, CancellationToken) 替代。)

public:
 override IAsyncResult ^ BeginWrite(cli::array <System::Byte> ^ buffer, int offset, int count, AsyncCallback ^ callback, System::Object ^ state);
public override IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback? callback, object? state);
public override IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback callback, object state);
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[]

包含要寫入目前資料流之資料的緩衝區。

offset
Int32

buffer 中以零起始的位元組位移,即開始將位元組複製到目前資料流的位置。

count
Int32

寫入的最大位元組數。

callback
AsyncCallback

在非同步寫入作業完成時所呼叫的方法。

state
Object

使用者所提供的物件,其可以從其他要求中區分出這個特定非同步寫入的要求。

傳回

物件,這個物件會參考可能還在暫止中的非同步寫入。

例外狀況

buffer 長度減去 offset 小於 count

buffernull

offsetcount 為負。

資料流不支援寫入。

備註

在 .NET Framework 4 和舊版中,您必須使用 和 之類的BeginWriteEndWrite方法來實作異步檔案作業。 這些方法仍可在 .NET Framework 4.5 中使用以支援舊版程式代碼;不過,新的異步方法,例如 ReadAsyncWriteAsyncFlushAsync,可協助您更輕鬆地實作異步檔案作業。

EndWrite每個都必須從BeginWrite呼叫一次IAsyncResultEndWrite 將會封鎖直到 I/O 作業完成為止。

適用於