TcpClient.ReceiveTimeout 屬性

定義

取得或設定時間值,TcpClient 一旦啟始讀取作業後,將據此等待以接收資料。Gets or sets the amount of time a TcpClient will wait to receive data once a read operation is initiated.

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

屬性值

連接的逾時值,以毫秒為單位。The time-out value of the connection in milliseconds. 預設值為 0。The default value is 0.

範例

下列程式碼範例會設定並取得接收時間。The following code example sets and gets the receive time out.

// 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

備註

屬性會決定Read方法將封鎖的時間量,直到它能夠接收資料為止。 ReceiveTimeoutThe ReceiveTimeout property determines the amount of time that the Read method will block until it is able to receive data. 這次的測量單位為毫秒。This time is measured in milliseconds. 如果超時時間在成功完成之前Read過期, TcpClientIOException會擲回。If the time-out expires before Read successfully completes, TcpClient throws a IOException. 預設不會有任何超時時間。There is no time-out by default.

適用於

另請參閱