Udostępnij przez


DataServiceContext.BeginExecute Metoda

Definicja

Asynchronicznie wysyła żądanie do usługi danych w celu wykonania określonego identyfikatora URI.

Przeciążenia

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

Asynchronicznie wysyła żądanie do usługi danych w celu pobrania następnej strony danych w wynikach zapytania stronicowanego.

BeginExecute<TElement>(Uri, AsyncCallback, Object)

Asynchronicznie wysyła żądanie, aby to wywołanie nie blokowało przetwarzania podczas oczekiwania na wyniki z usługi.

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

Asynchronicznie wysyła żądanie do usługi danych w celu pobrania następnej strony danych w wynikach zapytania stronicowanego.

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

Parametry typu

T

Typ zwracany przez zapytanie.

Parametry

continuation
DataServiceQueryContinuation<T>

DataServiceQueryContinuation<T> Obiekt reprezentujący następną stronę danych do zwrócenia z usługi danych.

callback
AsyncCallback

Delegowanie do wywoływania, gdy wyniki są dostępne do użycia przez klienta.

state
Object

Obiekt stanu zdefiniowany przez użytkownika przekazany do wywołania zwrotnego.

Zwraca

Element IAsyncResult reprezentujący stan operacji.

Uwagi

Podany DataServiceQueryContinuation<T> obiekt zawiera identyfikator URI, który po wykonaniu zwraca następną stronę danych w wyniku zapytania.

Dotyczy

BeginExecute<TElement>(Uri, AsyncCallback, Object)

Asynchronicznie wysyła żądanie, aby to wywołanie nie blokowało przetwarzania podczas oczekiwania na wyniki z usługi.

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

Parametry typu

TElement

Typ zwracany przez zapytanie.

Parametry

requestUri
Uri

Identyfikator URI, do którego zostanie wysłane żądanie zapytania. Identyfikator URI może być dowolnym prawidłowym identyfikatorem URI usługi danych; może zawierać $ parametry zapytania.

callback
AsyncCallback

Delegowanie do wywoływania, gdy wyniki są dostępne do użycia przez klienta.

state
Object

Obiekt stanu zdefiniowany przez użytkownika przekazany do wywołania zwrotnego.

Zwraca

Obiekt używany do śledzenia stanu operacji asynchronicznej.

Przykłady

W poniższym przykładzie pokazano, jak wykonać zapytanie asynchroniczne przez wywołanie BeginExecute metody w celu uruchomienia zapytania. Delegat wbudowany wywołuje metodę EndExecute , aby wyświetlić wyniki zapytania. W tym przykładzie użyto DataServiceContext narzędzia Add Service Reference tool opartego na usłudze danych Northwind, która jest tworzona po zakończeniu Usługi danych programu WCF .

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

Uwagi

Zwrócony IAsyncResult obiekt służy do określania, kiedy operacja asynchroniczna została ukończona. Aby uzyskać więcej informacji, zobacz Operacje asynchroniczne.

Metoda BeginExecute używa tej samej semantyki co Executemetoda , jednak ta metoda asynchronicznie wysyła żądanie, aby to wywołanie nie blokowało przetwarzania podczas oczekiwania na wyniki z usługi. Zgodnie ze standardowym wzorcem asynchronicznym początku-end, podane wywołanie zwrotne jest wywoływane po pobraniu wyników zapytania.

Zobacz też

Dotyczy