代码如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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); } } } |
运行结果如下
1 2 3 |
OK OK 请按任意键继续. . . |