这是我的代码:
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);
}
}
虽然说了50,但是该应用程序将冻结,直到一切完成。它肯定可以正常工作,并且从该站点记录消息的控制台也可以正常工作,但是它只是冻结了,这意味着在执行操作时,我无法执行诸如更新文本值和字符串之类的操作。
有什么办法可以使应用程序/ UI在发出这些Web请求时不会冻结?