Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.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# 程序在发出web请求时冻结_C# - Fatal编程技术网

C# 程序在发出web请求时冻结

C# 程序在发出web请求时冻结,c#,C#,这是我的代码: partial void runactivity (Foundation.NSObject sender) { string[] links; links = new string[amount]; for (int i = 0; i < links.Length; i++) { email = $"test123{RandomString(10)}@gmail.com"; links[i] = "http:

这是我的代码:

partial void runactivity (Foundation.NSObject sender)
{
    string[] links;

    links = new string[amount];
    for (int i = 0; i < links.Length; i++)
    {
        email = $"test123{RandomString(10)}@gmail.com";
        links[i] = "http://" + serverIP
            + ":" + serverPort + "/account/register?isAgeVerified=1&entrytag=&ignore=77240&newPassword=test123&newGUID="
          + email + "&guid=597BFBCFA0E1C4195FD6E8392557CD960361878D%22";
    }
    for (int i = 0; i < links.Length; i++) 
    {
        var request    = WebRequest.Create(links[i]);
        var response   = (HttpWebResponse)request.GetResponse();
        var dataStream = response.GetResponseStream();                    
        var reader     = new StreamReader(dataStream);
        var responseFromServer = reader.ReadToEnd();

        Activity++;
        Console.WriteLine ("Account " + Activity + ": " +  responseFromServer);
    }
}
部分无效运行活动(Foundation.NSObject发送方)
{
字符串[]链接;
链接=新字符串[金额];
for(int i=0;i
当输入50的数量时,应用程序会冻结,直到所有内容都完成。它肯定能工作,控制台记录来自站点的消息也能工作,但它只是冻结了,这意味着我不能在操作发生时更新文本值和字符串


有什么方法可以使应用程序/UI在发出这些web请求时不会冻结?

异步任务是您的朋友。interwebz上有很多很好的教程。我以前搜索过,但没有找到任何有用的详细解释,不一定是预先编写的代码。有什么建议我可以用来学习它吗?@AmbitionRotMG你在使用哪个GUI API?这是一个Mac,使用Xamarin.Mac,Visual Studio for Mac附带的一个。可能是