大家好,
请问各位高手,方式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;
}
区别 一个是同步的方法,一个是异步的;异步不会阻塞主线程,而同步会阻塞主线程