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

定義

開始非同步的讀取作業。 (請考慮使用 ReadAsync(Byte[], Int32, Int32) 方法替代。)

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

參數

bufferarray
Byte[]

要讀入資料的位元組陣列。

offset
Int32

要開始從數據流讀取數據的位元移。

count
Int32

要讀取的最大位元組數。

asyncCallback
AsyncCallback

選擇性的非同步回呼,在讀取作業完成時呼叫。

asyncState
Object

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

傳回

物件,表示可能還在暫止中的非同步讀取作業。

例外狀況

嘗試非同步讀取的方法超越資料流結尾,或發生了磁碟錯誤。

一或多個引數無效。

關閉資料流後呼叫了方法。

目前的 DeflateStream 實作不支援讀取作業。

無法完成此呼叫。

備註

重要

從 .NET 6 開始,這個方法可能不會讀取所要求的位元元組數目。 如需詳細資訊,請參閱 DeflateStream、GZipStream 和 CryptoStream 中的部分和零位元組讀取

從 .NET Framework 4.5 開始,您可以使用 方法來執行異步讀取作業ReadAsync。 此方法 BeginRead 仍可在目前的版本中使用,以支援舊版程式代碼;不過,您可以使用新的異步方法,更輕鬆地實作異步 I/O 作業。 如需詳細資訊,請參閱非同步檔案 I/O

將傳 IAsyncResult 回值傳遞至 EndRead 數據流的 方法,以判斷已讀取的位元元組數目,以及釋放用於讀取的操作系統資源。 您可以使用呼叫 BeginRead 的相同程式代碼,或在傳遞至 BeginRead的回呼中執行此動作。

發出異步讀取或寫入作業時,數據流中的目前位置會更新,而不是在 I/O 作業完成時更新。

多個同時異步要求會轉譯要求完成順序不確定。

CanRead使用屬性來判斷目前的 DeflateStream 物件是否支援讀取。

如果數據流已關閉,或您傳遞無效的自變數,則會立即從 BeginRead擲回例外狀況。 異步讀取要求期間發生的錯誤,例如 I/O 要求期間的磁碟失敗,會在線程集區線程上發生,並在呼叫 EndRead時擲回例外狀況。

適用於