代码如下
using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var x = new HttpClient(); var t1 = x.GetAsync("http://www.baidu.com"); var t2 = x.GetAsync("http://www.zhihu.com"); Task.WaitAll(t1, t2); Console.WriteLine(t1.Result.StatusCode); Console.WriteLine(t2.Result.StatusCode); } } }
运行结果如下
OK OK 请按任意键继续. . .