![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgs1p7oy4mtYypx8Cu7ymdTwb8scsOPZ9MjMqcT25yIReDzozySpbUMvlYFlG6-Y5bcsoW-F9zHsJ_YGJzH9zPaUqz-McYU6XLKyAxWAguYS4vPwJbOvhWoxDJBDxpktDg806gdZGNKWc8/w135-h135/sharp.png)
WebClientを使用していてタイムアウトがないことに気づきました。
以下のように派生クラスを作ることででタイムアウト有りで使用できます。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
namespace WebClientWithTimeout
{
class WebClientWithTimeout : WebClient
{
private int timeout = 60000;
public int Timeout
{
get
{
return timeout;
}
set
{
timeout = value;
}
}
protected override WebRequest GetWebRequest(Uri uri)
{
WebRequest w = base.GetWebRequest(uri);
w.Timeout = timeout;
return w;
}
}
}
0 件のコメント :
コメントを投稿