這裏是我的代碼如何同時運行多個Web客戶端?
try
{
for (int i = 0; i < RichTextbox2.Lines.Length; i++)
{
var length = urlwebapi.Lines.Length;
{
WebClient f = new WebClient();
dynamic read = f.DownloadString(urlwebapi.Lines[(i % length)] + RichTextbox2.Lines[i]);
JObject o = JObject.Parse(read);
}
}
}
catch (WebException e)
{
MessageBox.Show(e.Message);
}
MessageBox.Show("done");
樣品urlwebapi
http://example1.com/api.php?ex=
http://example2.com/api.php?ex=
http://example3.com/api.php?ex=
http://example4.com/api.php?ex=
http://example5.com/api.php?ex=
的代碼只能在同一時間在urlwebapi運行一個。怎麼辦時,在同一時間
看看[DownloadStringAsync](https://msdn.microsoft.com/de-de/library/system.net.webclient.downloadstringasync(v = vs.110).aspx)。這應該可以幫助你處理多個請求。 –