FtpWebRequest.Timeout プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
要求に対するミリ秒単位の待機時間を取得または設定します。
public:
virtual property int Timeout { int get(); void set(int value); };
public override int Timeout { get; set; }
member this.Timeout : int with get, set
Public Overrides Property Timeout As Integer
プロパティ値
Int32要求がタイムアウトするまで待機するミリ秒数を含む 値。既定値は ですInfinite。
例外
指定された値が 0 未満で、Infinite ではありません。
既に処理中の要求で、このプロパティに対して新しい値が指定されました。
例
次のコード例では、このプロパティを設定します。
public static bool UploadUniqueFileOnServer (Uri serverUri, string fileName)
{
// The URI described by serverUri should use the ftp:// scheme.
// It contains the name of the directory on the server.
// Example: ftp://contoso.com.
//
// The fileName parameter identifies the file containing the data to be uploaded.
if (serverUri.Scheme != Uri.UriSchemeFtp)
{
return false;
}
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
request.Method = WebRequestMethods.Ftp.UploadFileWithUniqueName;
// Set a time limit for the operation to complete.
request.Timeout = 600000;
// Copy the file contents to the request stream.
const int bufferLength = 2048;
byte[] buffer = new byte[bufferLength];
int count = 0;
int readBytes = 0;
FileStream stream = File.OpenRead(fileName);
Stream requestStream = request.GetRequestStream();
do
{
readBytes = stream.Read(buffer, 0, bufferLength);
requestStream.Write(buffer, 0, bufferLength);
count += readBytes;
}
while (readBytes != 0);
Console.WriteLine ("Writing {0} bytes to the stream.", count);
// IMPORTANT: Close the request stream before sending the request.
requestStream.Close();
FtpWebResponse response = (FtpWebResponse) request.GetResponse();
Console.WriteLine("Upload status: {0}, {1}",response.StatusCode, response.StatusDescription);
Console.WriteLine ("File name: {0}", response.ResponseUri);
response.Close();
return true;
}
注釈
無限の値を指定するには、 プロパティを Timeout (-1) に Infinite 設定します。 これが既定値です。
Timeout は、 メソッドで行われた GetResponse 同期要求が応答を待機し、メソッドがストリームを待機する GetRequestStream ミリ秒数です。 リソースがタイムアウト期間内に応答しない場合、要求は プロパティを に設定して StatusTimeoutをWebExceptionスローします。
、BeginGetRequestStream、、または BeginGetResponse メソッドを呼び出した後に GetRequestStreamを変更Timeoutすると、例外がInvalidOperationException発生GetResponseします。
ドメイン ネーム システム (DNS) クエリが返されるかタイムアウトするまでに最大 15 秒かかる場合があります。要求に解決が必要なホスト名が含まれており、15 秒未満の値に設定 Timeout した場合は、 がスローされて WebException 要求のタイムアウトが示されるまでに 15 秒以上かかることがあります。