我用例子的形式asp.net here异步等待,或只是任务<T>
于是,我问我,什么2码的区别:
public class ServiceTest
{
public Task<List<Widget>> WidgetsAsync(CancellationToken cancellationToken = default(CancellationToken))
{
var widgetService = new WidgetService();
return widgetService.GetWidgetsAsync(cancellationToken);
}
public Task<List<Product>> ProductAsync(CancellationToken cancellationToken = default(CancellationToken))
{
var prodService = new ProductService();
return prodService.GetProductsAsync(cancellationToken);
}
public Task<List<Gizmo>> GizmoAsync(CancellationToken cancellationToken = default(CancellationToken))
{
var gizmoService = new GizmoService();
return gizmoService.GetGizmosAsync(cancellationToken);
}
}
和
public class ServiceTest
{
public async Task<List<Widget>> WidgetsAsync(CancellationToken cancellationToken = default(CancellationToken))
{
var widgetService = new WidgetService();
return await widgetService.GetWidgetsAsync(cancellationToken);
}
public async Task<List<Product>> ProductAsync(CancellationToken cancellationToken = default(CancellationToken))
{
var prodService = new ProductService();
return await prodService.GetProductsAsync(cancellationToken);
}
public async Task<List<Gizmo>> GizmoAsync(CancellationToken cancellationToken = default(CancellationToken))
{
var gizmoService = new GizmoService();
return await gizmoService.GetGizmosAsync(cancellationToken);
}
}
消逝时间是完全一样的我.. 我开始与异步,所以也许这是一个愚蠢的问题,但我想确定之前采取一个不好的方向:)
谢谢你补充一点。 –