言語

DataServiceContext.BeginExecute メソッド

定義

特定の URI を実行する要求を非同期的にデータ サービスに送信します。

オーバーロード

名前 説明
BeginExecute<T>(DataServiceQueryContinuation<T>, AsyncCallback, Object)

ページングされたクエリ結果内のデータの次のページを取得する要求を非同期的にデータ サービスに送信します。

BeginExecute<TElement>(Uri, AsyncCallback, Object)

サービスからの結果を待機している間、この呼び出しで処理がブロックされないように、要求を非同期に送信します。

BeginExecute<T>(DataServiceQueryContinuation<T>, AsyncCallback, Object)

ページングされたクエリ結果内のデータの次のページを取得する要求を非同期的にデータ サービスに送信します。

public:
generic <typename T>
 IAsyncResult ^ BeginExecute(System::Data::Services::Client::DataServiceQueryContinuation<T> ^ continuation, AsyncCallback ^ callback, System::Object ^ state);
public IAsyncResult BeginExecute<T>(System.Data.Services.Client.DataServiceQueryContinuation<T> continuation, AsyncCallback callback, object state);
member this.BeginExecute : System.Data.Services.Client.DataServiceQueryContinuation<'T> * AsyncCallback * obj -> IAsyncResult
Public Function BeginExecute(Of T) (continuation As DataServiceQueryContinuation(Of T), callback As AsyncCallback, state As Object) As IAsyncResult

型パラメーター

T

クエリによって返される型。

パラメーター

continuation
DataServiceQueryContinuation<T>

データ サービスから返されるデータの次のページを表す DataServiceQueryContinuation<T> オブジェクト。

callback
AsyncCallback

クライアントで結果を使用できる場合に呼び出すデリゲート。

state
Object

コールバックに渡されるユーザー定義状態オブジェクト。

返品

操作の状態を表す IAsyncResult

注釈

指定された DataServiceQueryContinuation<T> オブジェクトには、実行されると、クエリ結果内のデータの次のページを返す URI が含まれています。

適用対象

BeginExecute<TElement>(Uri, AsyncCallback, Object)

サービスからの結果を待機している間、この呼び出しで処理がブロックされないように、要求を非同期に送信します。

public:
generic <typename TElement>
 IAsyncResult ^ BeginExecute(Uri ^ requestUri, AsyncCallback ^ callback, System::Object ^ state);
public IAsyncResult BeginExecute<TElement>(Uri requestUri, AsyncCallback callback, object state);
member this.BeginExecute : Uri * AsyncCallback * obj -> IAsyncResult
Public Function BeginExecute(Of TElement) (requestUri As Uri, callback As AsyncCallback, state As Object) As IAsyncResult

型パラメーター

TElement

クエリによって返される型。

パラメーター

requestUri
Uri

クエリ要求の送信先となる URI。 URI には、任意の有効なデータ サービス URI を指定できます。 $ クエリ パラメーターを含めることができます。

callback
AsyncCallback

クライアントで結果を使用できる場合に呼び出すデリゲート。

state
Object

コールバックに渡されるユーザー定義状態オブジェクト。

返品

非同期操作の状態を追跡するために使用されるオブジェクト。

次の例では、 BeginExecute メソッドを呼び出して非同期クエリを実行してクエリを開始する方法を示します。 インライン デリゲートは、 EndExecute メソッドを呼び出してクエリ結果を表示します。 この例では、Northwind データ サービスに基づいてサービス参照の追加ツールによって生成された DataServiceContext を使用します。これは、WCF Data Services を完了したときに作成されます。

public static void BeginExecuteCustomersQuery()
{
    // Create the DataServiceContext using the service URI.
    NorthwindEntities context = new NorthwindEntities(svcUri);

    // Define the query to execute asynchronously that returns
    // all customers with their respective orders.
    DataServiceQuery<Customer> query = (DataServiceQuery<Customer>)(from cust in context.Customers.Expand("Orders")
                                       where cust.CustomerID == "ALFKI"
                                       select cust);

    try
    {
        // Begin query execution, supplying a method to handle the response
        // and the original query object to maintain state in the callback.
        query.BeginExecute(OnCustomersQueryComplete, query);
    }
    catch (DataServiceQueryException ex)
    {
        throw new ApplicationException(
            "An error occurred during query execution.", ex);
    }
}

// Handle the query callback.
private static void OnCustomersQueryComplete(IAsyncResult result)
{
    // Get the original query from the result.
    DataServiceQuery<Customer> query =
        result as DataServiceQuery<Customer>;

    foreach (Customer customer in query.EndExecute(result))
    {
        Console.WriteLine("Customer Name: {0}", customer.CompanyName);
        foreach (Order order in customer.Orders)
        {
            Console.WriteLine("Order #: {0} - Freight $: {1}",
                order.OrderID, order.Freight);
        }
    }
}
Public Shared Sub BeginExecuteCustomersQuery()
    ' Create the DataServiceContext using the service URI.
    Dim context = New NorthwindEntities(svcUri)

    ' Define the delegate to callback into the process
    Dim callback As AsyncCallback = AddressOf OnCustomersQueryComplete

    ' Define the query to execute asynchronously that returns 
    ' all customers with their respective orders.
    Dim query As DataServiceQuery(Of Customer) =
    context.Customers.Expand("Orders")

    Try
        ' Begin query execution, supplying a method to handle the response
        ' and the original query object to maintain state in the callback.
        query.BeginExecute(callback, query)
    Catch ex As DataServiceQueryException
        Throw New ApplicationException(
                "An error occurred during query execution.", ex)
    End Try
End Sub
' Handle the query callback.
Private Shared Sub OnCustomersQueryComplete(ByVal result As IAsyncResult)
    ' Get the original query from the result.
    Dim query As DataServiceQuery(Of Customer) =
        CType(result.AsyncState, DataServiceQuery(Of Customer))

    ' Complete the query execution.
    For Each customer As Customer In query.EndExecute(result)
        Console.WriteLine("Customer Name: {0}", customer.CompanyName)
        For Each order As Order In customer.Orders
            Console.WriteLine("Order #: {0} - Freight $: {1}",
                    order.OrderID, order.Freight)
        Next
    Next
End Sub

注釈

返された IAsyncResult オブジェクトは、非同期操作がいつ完了したかを判断するために使用されます。 詳細については、「 非同期操作」を参照してください。

メソッドBeginExecuteExecuteと同じセマンティクスを使用しますが、このメソッドは非同期的に要求を送信するため、この呼び出しはサービスからの結果を待機している間に処理をブロックしません。 標準の begin-end 非同期パターンに従って、クエリ結果が取得されると、指定されたコールバックが呼び出されます。

こちらもご覧ください

適用対象