Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多线程处理时,C#Webrequest响应非常慢_C#_Httpwebrequest_Webrequest - Fatal编程技术网

多线程处理时,C#Webrequest响应非常慢

多线程处理时,C#Webrequest响应非常慢,c#,httpwebrequest,webrequest,C#,Httpwebrequest,Webrequest,因此,我有一个程序,将发送许多网络请求。它发送如下信息: be.AsParallel().WithDegreeOfParallelism(1).ForAll(Send); 这将发送它并将其添加到线程池 private void Send(string emailName) { ServicePointManager.DefaultConnectionLimit = int.MaxValue; ServicePointManager.Expect100Contin

因此,我有一个程序,将发送许多网络请求。它发送如下信息:

be.AsParallel().WithDegreeOfParallelism(1).ForAll(Send);
这将发送它并将其添加到线程池

private void Send(string emailName)
{
        ServicePointManager.DefaultConnectionLimit = int.MaxValue;
        ServicePointManager.Expect100Continue = false;
        Console.Title =
            $"{emailName}{_domain} /::/ {_tries} /::/ {Sw.Elapsed.ToString("dd\\:hh\\:mm\\:ss")}";
        _tries++;

        ThreadPool.QueueUserWorkItem((o) =>
        {
            var request =
                (HttpWebRequest)
                    WebRequest.Create("http://www.realmofthemadgod.com/account/forgotPassword?guid=" + emailName +
                                      _domain);
            request.Proxy = null;
            request.Method = "GET";
            request.Timeout = 60000;
            request.KeepAlive = false;

            var response = (HttpWebResponse) request.GetResponse();

            // ReSharper disable once AssignNullToNotNullAttribute
            using (var reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII))
            {
                if (reader.ReadToEnd() != "<Success/>") return;

                if (logToFile)
                {
                    lock (_syncRoot)
                    {
                        var reader1 = File.ReadAllText(@"C:\Users\" + _userPath + @"\Desktop\accounts.txt");
                        using (var writer = File.AppendText(@"C:\Users\" + _userPath + @"\Desktop\accounts.txt")
                            )
                        {
                            if (!reader1.Contains(emailName + _domain))
                                writer.WriteLine(emailName + _domain);
                            writer.Close();
                        }
                    }
                }

                Console.WriteLine($"Found: " + emailName + _domain);
                _synthesizer.Speak("New account found");
            }
        });
    }
private void Send(字符串emailName)
{
ServicePointManager.DefaultConnectionLimit=int.MaxValue;
ServicePointManager.Expect100Continue=false;
控制台.标题=
$“{emailName}{u domain}/:://{u tries}/:://{Sw.appeased.ToString(“dd\\\:hh\\:mm\\:ss”);
_尝试++;
ThreadPool.QueueUserWorkItem((o)=>
{
var请求=
(HttpWebRequest)
WebRequest.Create(“http://www.realmofthemadgod.com/account/forgotPassword?guid=“+电子邮件名称+
_域名);
Proxy=null;
request.Method=“GET”;
请求超时=60000;
request.KeepAlive=false;
var response=(HttpWebResponse)request.GetResponse();
//ReSharper禁用一次分配NullToNotNullAttribute
使用(var reader=newstreamreader(response.GetResponseStream(),Encoding.ASCII))
{
if(reader.ReadToEnd()!=“”)返回;
if(日志文件)
{
锁定(\u syncRoot)
{
var reader1=File.ReadAllText(@“C:\Users\”+_userPath++“\Desktop\accounts.txt”);
使用(var writer=File.AppendText(@“C:\Users\”+\u userPath++“\Desktop\accounts.txt”)
)
{
如果(!reader1.Contains(emailName+_域))
writer.WriteLine(emailName+_域);
writer.Close();
}
}
}
Console.WriteLine($”找到:“+emailName+\u域);
_synthesizer.Speak(“找到新帐户”);
}
});
}
如果请求返回“Success/”,它基本上会告诉我

当我让它运行时,它将在大约0.5秒内完成700个请求,但随后需要几分钟才能告诉我结果。 我想知道如何做,以便在发送请求时,它会告诉我是否返回“Success/”,而不是5分钟后