NetworkStream.WriteTimeout プロパティ
アセンブリ: System (system.dll 内)

Dim instance As NetworkStream Dim value As Integer value = instance.WriteTimeout instance.WriteTimeout = value
/** @property */ public int get_WriteTimeout () /** @property */ public void set_WriteTimeout (int value)
public override function get WriteTimeout () : int public override function set WriteTimeout (value : int)
書き込み操作が失敗するまでの経過時間 (ミリ秒単位) を指定する Int32。既定値は Infinite で、書き込み操作がタイムアウトしないことを示します。


このプロパティで指定した時間内に書き込み操作が完了しない場合、書き込み操作は IOException をスローします。
![]() |
---|
このプロパティは、Write メソッドの呼び出しで実行される同期の書き込み操作だけに適用されます。このプロパティは、BeginWrite メソッドの呼び出しで実行される非同期書き込みには適用されません。 |

ネットワーク ストリームの書き込みタイムアウトを 10 ミリ秒に設定するコード例を次に示します。
using System; using System.Text; using System.Net; using System.Net.Sockets; namespace Examples.System.Net { public class TCPListenerExample { public static void Main() { // Create the server side connection and // start listening for clients. TcpListener tcpListener = new TcpListener(IPAddress.Any ,11000); tcpListener.Start(); Console.WriteLine("Waiting for a connection...."); // Accept the pending client connection. TcpClient tcpClient = tcpListener.AcceptTcpClient(); Console.WriteLine("Connection accepted."); // Get the stream to write the message // that will be sent to the client. NetworkStream networkStream = tcpClient.GetStream(); string responseString = "Hello."; // Set the write timeout to 10 millseconds. networkStream.WriteTimeout = 10; // Convert the message to a byte array and sent it to the client. Byte[] sendBytes = Encoding.UTF8.GetBytes(responseString); networkStream.Write(sendBytes, 0, sendBytes.Length); Console.WriteLine("Message Sent."); // Close the connection to the client. tcpClient.Close(); // Stop listening for incoming connections // and close the server. tcpListener.Stop(); } } }
#using <System.dll> using namespace System; using namespace System::Text; using namespace System::Net; using namespace System::Net::Sockets; int main() { // Create the server side connection and // start listening for clients. TcpListener^ tcpListener = gcnew TcpListener(IPAddress::Any, 11000); tcpListener->Start(); Console::WriteLine("Waiting for a connection...."); // Accept the pending client connection. TcpClient^ tcpClient = tcpListener->AcceptTcpClient(); Console::WriteLine("Connection accepted."); // Get the stream to write the message // that will be sent to the client. NetworkStream^ networkStream = tcpClient->GetStream(); String^ responseString = "Hello."; // Set the write timeout to 10 millseconds. networkStream->WriteTimeout = 10; // Convert the message to a byte array and sent it to the client. array<Byte>^ sendBytes = Encoding::UTF8->GetBytes(responseString); networkStream->Write(sendBytes, 0, sendBytes->Length); Console::WriteLine("Message Sent."); // Close the connection to the client. tcpClient->Close(); // Stop listening for incoming connections // and close the server. tcpListener->Stop(); }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からNetworkStream.WriteTimeout プロパティを検索する場合は、下記のリンクをクリックしてください。

- NetworkStream.WriteTimeout プロパティのページへのリンク