我正在运行以下代码来启动我的线程:
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 线程之后请求开始超时..
知道如何解决这个问题吗?:)