共用方式為


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 到期, TcpClient 則會 IOException擲回 。 預設不會逾時。

適用於

另請參閱