使用Task.Run创建异步API

使用Task.Run创建异步API,api,asynchronous,async-await,Api,Asynchronous,Async Await,有什么(反模式)可以阻止我进行这样的API调用的异步版本吗 public IItem GetItem(int id) { var result = SomeLengthyServiceCall(id); return result; } public async Task<IItem> GetItemAsync(int id) { return await Task.Run(() => this.GetItem(id)); } public项目Get

有什么(反模式)可以阻止我进行这样的API调用的异步版本吗

public IItem GetItem(int id)
{
    var result = SomeLengthyServiceCall(id);
    return result;
}

public async Task<IItem> GetItemAsync(int id)
{
    return await Task.Run(() => this.GetItem(id));
}
public项目GetItem(int-id)
{
var结果=SomeLengthyServiceCall(id);
返回结果;
}
公共异步任务GetItemAsync(int id)
{
返回等待任务。运行(()=>this.GetItem(id));
}

是的,这是一种反模式;请参阅Stephen Toub的优秀博客文章

简而言之,只有自然异步的方法才应该有异步API