写了个例子程序
using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace Chapter1.Threads
{
public static class Program
{
public static void Main()
{
string result = DownloadContent().Result;
Console.WriteLine(result);
}
public static async Task<string> DownloadContent()
{
using(HttpClient client = new HttpClient())
{
string result = await client.GetStringAsync("http://www.microsoft.com");
return result;
}
}
}
}
但是用mcs 编译时,报错
async1.cs(2,18): error CS0234: The type or namespace name `Http' does not exist in the namespace `System.Net'. Are you missing `System.Net.Http' assembly reference?
解决方法:用/reference 加上依赖的DLL
mcs /reference:System.Net.Http async1.cs