首页 新闻 会员 周边 捐助

async,await 作用

0
悬赏园豆:5 [待解决问题]

大家好,

请问各位高手,方式1与方式2有什么区别。

 

方式1

public async Task<IDictionary<string, object>> Get()
{
HttpConfiguration configuration = new HttpConfiguration();
configuration.Routes.MapHttpRoute("default", "wheather/{areaCode}/{days}");
MyHttpRoutingDispatcher dispatcher =
new MyHttpRoutingDispatcher(configuration);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://www.artech.com/wheather/010/2");

await dispatcher.SendAsync(request, CancellationToken.None);
IHttpRouteData routeData = request.GetRouteData();
return routeData.Values;
}

方式2【去除async,await

public IDictionary<string, object> Get()
{
HttpConfiguration configuration = new HttpConfiguration();
configuration.Routes.MapHttpRoute("default", "wheather/{areaCode}/{days}");
MyHttpRoutingDispatcher dispatcher =
new MyHttpRoutingDispatcher(configuration);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://www.artech.com/wheather/010/2");

dispatcher.SendAsync(request, CancellationToken.None);
IHttpRouteData routeData = request.GetRouteData();
return routeData.Values;
}

共同学习,共同进步的主页 共同学习,共同进步 | 初学一级 | 园豆:132
提问于:2015-11-17 15:06
< >
分享
所有回答(1)
0

 区别 一个是同步的方法,一个是异步的;异步不会阻塞主线程,而同步会阻塞主线程

xmj112288 | 园豆:126 (初学一级) | 2015-11-18 12:47
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册