标签:
public static async Task<string> GetStringAsync() { //System.Console.WriteLine(Thread.CurrentThread.Name + " 是否池化线程:" + Thread.CurrentThread.IsThreadPoolThread); System.Console.WriteLine("GetStringAsync is start"); var client = new WebClient(); var result = await client.DownloadStringTaskAsync(new Uri(url)); System.Console.WriteLine("GetStringAsync is end"); return result; }
static void Main(string[] args) { Console.WriteLine("main is start"); Thread.CurrentThread.Name = "主线程"; Task<string> s = AsyncTest.GetStringAsync(); var str=AsyncTest.GetString(); Console.WriteLine(str); Console.WriteLine("main function is going to complete"); Console.WriteLine(s.Result); Console.Read(); }
Task<string> s = Task.Run(() => { return AsyncTest.GetString(); });
标签:
原文地址:http://www.cnblogs.com/lihan829/p/5352181.html