NetworkStream.ReadTimeout 속성

정의

데이터를 기다리는 중 읽기 작업이 차단되는 시간을 가져오거나 설정합니다.

public:
 virtual property int ReadTimeout { int get(); void set(int value); };
public override int ReadTimeout { get; set; }
member this.ReadTimeout : int with get, set
Public Overrides Property ReadTimeout As Integer

속성 값

읽기 작업의 제한 시간(밀리초)을 지정하는 Int32입니다. 이 시간이 경과하면 읽기 작업이 실패합니다. 기본값인 Infinite는 읽기 작업에 제한 시간이 없음을 나타냅니다.

예외

지정한 값이 0보다 작거나 같고 Infinite가 아닌 경우

예제

다음 코드 예제에서는 네트워크 스트림의 읽기 제한 시간을 10밀리초로 설정합니다.

// Create a client that will connect to a
// server listening on the contosoServer computer
// at port 11000.
TcpClient tcpClient = new TcpClient();
tcpClient.Connect("contosoServer", 11000);
// Get the stream used to read the message sent by the server.
NetworkStream networkStream = tcpClient.GetStream();
// Set a 10 millisecond timeout for reading.
networkStream.ReadTimeout = 10;
// Read the server message into a byte buffer.
byte[] bytes = new byte[1024];
networkStream.Read(bytes, 0, 1024);
//Convert the server's message into a string and display it.
string data = Encoding.UTF8.GetString(bytes);
Console.WriteLine("Server sent message: {0}", data);
networkStream.Close();
tcpClient.Close();

설명

이 속성에 지정된 시간 내에 읽기 작업이 완료되지 않으면 읽기 작업은 을 IOExceptionthrow합니다.

참고

이 속성은 메서드를 호출 Read 하여 수행되는 동기 읽기에만 영향을 줍니다. 이 속성은 또는 ReadAsync 메서드를 호출하여 수행되는 비동기 읽기에 BeginRead 영향을 주지 않습니다.

적용 대상