TcpClient.ReceiveTimeout 属性

定义

获取或设置在初始化一个读取操作以后 TcpClient 等待接收数据的时间量。

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

属性值

连接的超时值(以毫秒为单位)。 默认值为 0。

示例

下面的代码示例设置并获取接收超时。

// Sets the receive time out using the ReceiveTimeout public property.
tcpClient->ReceiveTimeout = 5;

// Gets the receive time out using the ReceiveTimeout public property.
if ( tcpClient->ReceiveTimeout == 5 )
      Console::WriteLine( "The receive time out limit was successfully set {0}", tcpClient->ReceiveTimeout );
// Sets the receive time out using the ReceiveTimeout public property.
tcpClient.ReceiveTimeout = 5000;

// Gets the receive time out using the ReceiveTimeout public property.
if (tcpClient.ReceiveTimeout == 5000)
    Console.WriteLine ("The receive time out limit was successfully set " + tcpClient.ReceiveTimeout.ToString ());
' Sets the receive time out using the ReceiveTimeout public property.
tcpClient.ReceiveTimeout = 5

' Gets the receive time out using the ReceiveTimeout public property.
If tcpClient.ReceiveTimeout = 5 Then
   Console.WriteLine(("The receive time out limit was successfully set " + tcpClient.ReceiveTimeout.ToString()))
End If

注解

属性 ReceiveTimeout 确定方法在能够接收数据之前将阻塞的时间 Read 量。 此时间以毫秒为单位。 如果超时在成功完成之前 Read 过期, TcpClientIOException引发 。 默认情况下没有超时。

适用于

另请参阅