スレッドを開始するために次のコードを実行しています。
stpStartInfo.MaxWorkerThreads = Convert.ToInt32(parserThreadCount.Value);
stpStartInfo.MinWorkerThreads = 1;
_smartThreadPool2 = new Smart.SmartThreadPool(stpStartInfo);
string f = sourceFileName.Text;
int totCount = countLinesInFile(f);
using (StreamReader r = new StreamReader(f))
{
int iia = 0;
string line;
while ((line = r.ReadLine()) != null)
{
if (!string.IsNullOrEmpty(line))
{
_smartThreadPool2.QueueWorkItem(
new Amib.Threading.Func<string, int, int, int>(checkSource),
line, iia, totCount);
iia++;
}
}
}
私のスレッドは、この HttpWebRequest を実行しています:
try
{
HttpWebRequest _wReq;
HttpWebResponse _wResp;
System.IO.StreamReader _sr;
System.Text.ASCIIEncoding _enc = new System.Text.ASCIIEncoding();
_wReq = (HttpWebRequest)WebRequest.Create(PAGE_URL);
_wReq.CookieContainer = cookieCont;
_wReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
_wReq.ReadWriteTimeout = 10000;
_wReq.Timeout = 10000;
_wReq.ProtocolVersion = HttpVersion.Version10;
_wReq.KeepAlive = false;
_wResp = (HttpWebResponse)_wReq.GetResponse();
_sr = new System.IO.StreamReader(_wResp.GetResponseStream());
html = _sr.ReadToEnd();
_sr.Close();
_cookies = _wReq.CookieContainer;
_wResp.Close();
}
catch (WebException ex)
{
if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null)
{
var resp = (HttpWebResponse)ex.Response;
if (resp.StatusCode == HttpStatusCode.ServiceUnavailable)
{
}
}
}
それは完全に機能しますが、30ish スレッドの後、要求がタイムアウトし始めます..
これを回避する方法はありますか?:)