ExtensionMethod.NET Home of 881 C#, Visual Basic, F# and Javascript extension methods

QueryAsync

Returns a Task<IEnumerable<TResult>> to be used with the new async / await keyword.

Source

using System;
using System.Collections.Generic;
using System.Data.Services.Client;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bing
{
 public static class QueryExtensions
 {
 public static Task<IEnumerable<TResult>> QueryAsync<TResult>(this DataServiceQuery<TResult> query)
 {
 return Task<IEnumerable<TResult>>.Factory.FromAsync(query.BeginExecute, query.EndExecute, null);
 }
 }
}

Example

BingSearchContainer _bsc = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search/"));

var webQ = _bsc.Image("search", null, null, null, null, null);

var result = await webQ.QueryAsync() ;

Author: Sebastian Dau

Submitted on: 13 jun. 2012

Language: C#

Type: System.Data.Services.Client.DataServiceQuery<TResult>

Views: 10381