0

I'm trying to implement TaskCompletionSource to stop code executing until the dependency service method has completed, but am getting an error when trying to return the TaskCompletionSource result

 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);
 }

Call to dependency service:

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

the line return tcs.SetResult(items) gives an error:

Cannot implicitly convert type 'void' to 'System.Threading.Tasks.Task<System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<Ferret.Models.ImageListItem, Ferret.Models.IosImageModel>>>
Ryn9011
  • 179
  • 2
  • 17
  • I am struggling to see how this code can cause that error. Something is not what it seems, and has little to do with a dependency service. and more likely there is a GetImageListItems floating around that returns void – TheGeneral Sep 29 '20 at 04:08
  • What's the type of tcs.SetResult(items)? – nevermore Sep 29 '20 at 08:55

0 Answers0