从异步方法返回任务以外的对象



如何从异步方法返回任务以外的对象? 我在方法中做了一些异步工作,但我需要返回任务以外的内容或返回任务中的对象。我不知道。

法典:

public async Task<ICollection<KeyValuePair<int, IServiceProvider>>> GetGroupedSearchStrings(int shopId)
{
ICollection<KeyValuePair<int, ISearchString>> result = new Collection<KeyValuePair<int, ISearchString>>();
IEnumerable<ISearchString> ss = await ShopsExpressions.SearchString(this.Worker.GetRepo<SearchString>().DbSet).Where(s => s.Active && s.ShopId.Equals(shopId)).OrderBy(s => s.DateCreated).ToListAsync();
result.Add(new KeyValuePair<int, ISearchString>(1, DEMO));
return result;
}

异步函数应该返回一个任务。

调用任务时需要await任务。

var result = await GetGroupedSearchStrings(shopID);

最新更新