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>>>