public async Task <IEnumerable <Target> > GetTargets(string targetSetId, int page, int pageSize) { GoogleCredential cred = this.CreateCredentials(); var channel = new Channel(ProductSearchClient.DefaultEndpoint.Host, ProductSearchClient.DefaultEndpoint.Port, cred.ToChannelCredentials()); try { var client = ProductSearchClient.Create(channel); ListProductsInProductSetRequest request = new ListProductsInProductSetRequest { ProductSetName = new ProductSetName(this.options.Value.ProjectId, this.options.Value.LocationId, targetSetId), PageSize = pageSize, }; PagedAsyncEnumerable <ListProductsInProductSetResponse, Product> response = client.ListProductsInProductSetAsync(request); IEnumerable <Product> products = await response.AsAsyncEnumerable().ToArray(); IEnumerable <Target> targets = await Task.WhenAll(products.Select(p => this.LoadReferenceImagesAndMapToTarget(client, p, pageSize))); return(targets); } finally { await channel.ShutdownAsync(); } }