다음을 통해 공유


NetworkStream.BeginRead(Byte[], Int32, Int32, AsyncCallback, Object) 메서드

정의

에서 비동기 읽기를 시작합니다 NetworkStream.

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

매개 변수

buffer
Byte[]

에서 읽은 데이터를 저장할 메모리의 위치인 형식 ByteNetworkStream배열입니다.

offset
Int32

데이터 저장을 시작할 위치 buffer 입니다.

countsize
Int32

에서 읽을 바이트 수입니다 NetworkStream.

callback
AsyncCallback

AsyncCallback 완료될 때 BeginRead(Byte[], Int32, Int32, AsyncCallback, Object) 실행되는 대리자입니다.

state
Object

추가 사용자 정의 데이터를 포함하는 개체입니다.

반환

IAsyncResult 비동기 호출을 나타내는 값입니다.

예외

매개 변수는 buffer .입니다 null.

offset 매개 변수가 0보다 작습니다.

-또는-

offset 매개 변수가 매개 변수의 buffer 길이보다 큰 경우

-또는-

size 0보다 작습니다.

-또는-

size 값은 매개 변수의 buffer 값을 offset 뺀 길이보다 큽합니다.

내부가 닫혀 있습니다 Socket .

-또는-

네트워크에서 읽는 동안 오류가 발생했습니다.

-또는-

소켓에 액세스할 때 오류가 발생했습니다.

NetworkStream 닫혀 있습니다.

설명

중요합니다

호환성 API입니다. 새 개발에 APM (Begin/End) 메서드를 사용하지 않는 것이 좋습니다. 대신 작업 기반 해당 항목을 사용합니다.

작업 완료에 대한 알림을 받기 위해 AsyncCallback 구현 BeginRead 하는 콜백을 전달할 수 있습니다. 기본 네트워크 스택이 동기적으로 작업을 완료하는 경우 호출 BeginRead중에 콜백이 인라인으로 실행됩니다. 이 경우 반환 CompletedSynchronously 된 속성은 IAsyncResult 메서드가 동기적으로 완료되었음을 나타내도록 true 설정됩니다. 메서드에 AsyncState 전달된 상태 개체를 가져오려면 IAsyncResult 해당 속성을 BeginRead 사용합니다.

메서드를 BeginRead 호출 EndRead 하여 작업을 완료해야 합니다. 일반적으로 제공된 대리자가 메서드를 AsyncCallback 호출합니다. EndRead 는 작업이 완료될 때까지 호출 스레드를 차단합니다.

이 작업은 매개 변수에 지정된 count 바이트 수까지 사용 가능한 만큼의 데이터를 읽습니다.

메모

받는 IOException경우 속성을 확인 InnerException 하여 속성이 .에 의해 SocketException발생했는지 확인합니다. 그렇다면 속성을 사용하여 ErrorCode 특정 오류 코드를 가져옵니다.

동기화할 필요 없이 클래스 인스턴스 NetworkStream 에서 읽기 및 쓰기 작업을 동시에 수행할 수 있습니다. 쓰기 작업에 고유한 스레드가 하나 있고 읽기 작업에 고유한 스레드가 하나 있는 한 읽기 및 쓰기 스레드 간에 교차 간섭이 없고 동기화가 필요하지 않습니다.

적용 대상

추가 정보