0

我正在尝试实现 TaskCompletionSource 以停止代码执行,直到依赖服务方法完成,但是在尝试返回 TaskCompletionSource 结果时出现错误

 public interface IImageFetcher<T, K>
 {        
    Task<List<KeyValuePair<T, K>>> GetImageListItems();
 }  

 public Task<List<KeyValuePair<ImageListItem, IosImageModel>>> 
     GetImageListItems()
 {
      var tcs = new 
      TaskCompletionSource<List<KeyValuePair<ImageListItem, 
      IosImageModel>>>();
      .....
      return tcs.SetResult(items);
 }

调用依赖服务:

 List<KeyValuePair<ImageListItem, IosImageModel>> imageListItems = await DependencyService.Get<IImageFetcher<ImageListItem, IosImageModel>>().GetImageListItems();

return tcs.SetResult(items) 行给出错误:

Cannot implicitly convert type 'void' to 'System.Threading.Tasks.Task<System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<Ferret.Models.ImageListItem, Ferret.Models.IosImageModel>>>
4

0 回答 0